Right now, I'm doing:
function fn(arg) {
const foo = arg as SomeType;
...
}
Is there a way to do the type casting in the function argument? I.e. something like function fn(arg as SomeType)
Here's an example:
Promise.race([
Promise.resolve(1),
new Promise((_, fail) => {
setTimeout(fail, 1000);
}),
])
.then((res: number) => {
...
});
But TS throws:
Argument of type '(res: number) => void' is not assignable to parameter of type '(value: unknown) => void | PromiseLike<void>'.
Types of parameters 'res' and 'value' are incompatible.
Type 'unknown' is not assignable to type 'number'
Instead, I have to do:
.then((temp) => {
const res: number = temp as number;
...
});
SomeType?