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
I have a variable of a union type (A or B). I have a function with overloads for A and for B.
It seems definitely sensible to allow passing this variable to the function. But TS fails on compilation.
lib.ts(28,6): error TS2345: Argument of type 'A | B' is not assignable to parameter of type 'B'.
Type 'A' is not assignable to type 'B'.
Property 'bar' is missing in type 'A'.
I didn't test on all versions but I guess it doesn't depend on particular version as it's failing in the Playground.
I understand that instead of using overloads I can create a function with union type for argument:
function test(obj: A | B): boolean;
but in my case it's not acceptable. Actually the provided code is a simplified example of bigger problem.
I have a component with an option which type is string[] | Map<string> where Map is
export interface Map<T> {
[key: string]: T;
}
I need to pass this option to a function from Undescore like these ones:
I have a variable of a union type (A or B). I have a function with overloads for A and for B.
It seems definitely sensible to allow passing this variable to the function. But TS fails on compilation.
See Playground
Expected behavior:
No compile errors.
Actual behavior:
I didn't test on all versions but I guess it doesn't depend on particular version as it's failing in the Playground.
I understand that instead of using overloads I can create a function with union type for argument:
but in my case it's not acceptable. Actually the provided code is a simplified example of bigger problem.
I have a component with an option which type is
string[] | Map<string>
where Map isI need to pass this option to a function from Undescore like these ones:
The text was updated successfully, but these errors were encountered: