Open
Description
TypeScript Version: 2.8.0-dev.20180315
Search Terms:
infer conditional unify generic function
Code
type Apply1<T, V> = T extends (item: V) => infer R ? R : never;
type A1 = Apply1< (item: string) => string[] , string>;
type B1 = Apply1< <U>(item: U) => U[], string>;
type Apply2<T, V> = T extends (item: V, obj: infer R) => any ? R : never;
type A2 = Apply2< (item: string, obj: string[]) => any , string>;
type B2 = Apply2< <U>(item: U, obj: U[]) => any , string>;
type Apply3<T, V> = T extends (item: V, obj: infer R) => infer R ? R : never;
type A3 = Apply3< (item: string, obj: string[]) => string[] , string>;
type B3 = Apply3< <U>(item: U, obj: U[]) => U[] , string>;
{
"compilerOptions": {
"allowJs": true,
"target": "es6",
"module": "commonjs",
"outDir": "dest",
"strictNullChecks": true,
"jsx": "preserve",
"strictFunctionTypes": true
}
}
Expected behavior:
All A
and B
types are inferred to string[]
. For types B
, the type parameter U
should be unified with string
.
Actual behavior:
All B
types are inferred to {}[]
.
Related Issues:
#22615 (different problem, but similar input)