Currently, I am working on:
function fn(arg) {
const foo = arg as SomeType;
...
}
Is there a way to perform type casting directly in the function argument? For instance, something like function fn(arg as SomeType)
Here is an illustration:
Promise.race([
Promise.resolve(1),
new Promise((_, fail) => {
setTimeout(fail, 1000);
}),
])
.then((res: number) => {
...
});
However, TypeScript throws this error:
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 of that, I have to use:
.then((temp) => {
const res: number = temp as number;
...
});