Forcibly change a functions parameter type by casting itself.
It looked like
(<number>foo)(1)
Where
function foo( v : string )
You can't change the function param types but you can cast (type assert) the param you're passing to it to any:
function fn(obj: string) {
...
}
fn(1 as any);
But you can make the function more generic:
function fn(obj: string | number) {
...
}
fn(1);
fn("str");
You can also use generics:
function fn<T>(obj: T) {
...
}
fn(1);
fn("str");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With