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
type Test1 = 'foo';
type Test2 = 'bar';
type TUnion = Test1 | Test2;
interface TReturnForTest1 { }
interface TReturnForTest2 { }
function unionTypeTest(arg: Test1): TReturnForTest1;
function unionTypeTest(arg: Test2): TReturnForTest2;
function unionTypeTest(arg: TUnion): any {
return null;
}
const bar = unionTypeTest('foo' as TUnion); // Error: Type '"foo"' is not assignable to type '"bar"'.
The text was updated successfully, but these errors were encountered:
@mhegazy Thanks for the reply! Not sure I grok the scalability concerns though. I'd expect tsc would just check the declarations from top to bottom and use the first one that matches, no? (i.e., linear w/r to number of declaration overloads). Doesn't seem unscalable to me.
[email protected]
I'd like to write a polymorphic function whose return type is inferred based on string enum value of a parameter.
Is there a way to do that?
Here's my - probably quite naive - approach (which doesn't compile):
The text was updated successfully, but these errors were encountered: