You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because both overloads have the same argument count and same return type, we can instead write a non-overloaded version of the function:
functionlen(x: any[]|string){returnx.length;}
above has some problems in typescript playground:
No overload matches this call.
Overload 1 of 2, '(s: string): number', gave the following error.
Argument of type'number[] | "hello"' is not assignable to parameter of type'string'.
Type 'number[]' is not assignable to type'string'.
Overload 2 of 2, '(arr: any[]): number', gave the following error.
Argument of type'number[] | "hello"' is not assignable to parameter of type'any[]'.
Type 'string' is not assignable to type'any[]'.