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
typeType<Textends1|2>=Textends1 ? number :
Textends2 ? string :
never;typeFoo<Textends1|2>=(x: {a: T,b: Type<T>})=>void;functionfoo1(x: {a: 1,b: number}|{a: 2,b: string}){}functionfoo2(x: {a: 2,b: string}|{a: 1,b: number}){}functionbar<Textends1|2>(a: T,b: Foo<T>){}bar(1,foo1);// okbar(2,foo1);// error: Argument of type '2' is not assignable to parameter of type '1'.(2345)bar(1,foo2);// error: Argument of type '1' is not assignable to parameter of type '2'.(2345)bar(2,foo2);// ok
π Actual behavior
In bar, foo1 is always inferred to be Foo<1> and foo2 is always inferred to be Foo<2>
π Expected behavior
It is supposed to be no error there because foo1 and foo2 have the same type, which can satisfy all the four calls.
The text was updated successfully, but these errors were encountered:
Thanks. But I found it doesn't work if I use function overload instead of union type in nightly. Here is the code.
typeType<Textends1|2>=Textends1 ? number :
Textends2 ? string :
never;typeFoo<Textends1|2>=(x: {a: T,b: Type<T>})=>void;functionfoo1(x: {a: 1,b: number}): void;functionfoo1(x: {a: 2,b: string}): void;functionfoo1(x: any){}functionbar<Textends1|2>(a: T,b: Foo<T>){}bar(1,foo1);// error: Argument of type '1' is not assignable to parameter of type '2'.(2345)bar(2,foo1);// ok
Bug Report
π Search Terms
generic type argument inference
π Version & Regression Information
4.4.4
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
In
bar
,foo1
is always inferred to beFoo<1>
andfoo2
is always inferred to beFoo<2>
π Expected behavior
It is supposed to be no error there because
foo1
andfoo2
have the same type, which can satisfy all the four calls.The text was updated successfully, but these errors were encountered: