Closed
Description
Bug Report
π Search Terms
generic type argument inference
π Version & Regression Information
4.4.4
β― Playground Link
Playground link with relevant code
π» Code
type Type<T extends 1|2> =
T extends 1 ? number :
T extends 2 ? string :
never;
type Foo<T extends 1|2> = (x: {a: T, b: Type<T>}) => void;
function foo1(x: {a: 1, b: number} | {a: 2, b: string}) {}
function foo2(x: {a: 2, b: string} | {a: 1, b: number}) {}
function bar<T extends 1|2> (a: T, b: Foo<T>) {}
bar(1, foo1); // ok
bar(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.