TypeScript Version: 3.1.0-dev.20180831
Search Terms: infer, unused generic type
In below example infer behaves inconsistently when the generic type argument is unused.
It should either:
- infer {} for all cases due to some "unused hence ignore" logic
- "extends" should not assert it
- "expected behavior".
In real life scenario T is used to carry additional type info.
Code
type Unpack<A> = A extends Parent<infer T>? T : never;
interface Parent<T> {
//foo:T
}
interface Child extends Parent<string>{
bar
}
type Cousin = Parent<string> & {
baz
}
type PP = Parent<string>;
type T1 = Unpack<Parent<number>>; //T1 is number OK
type T2 = Unpack<Child>; //T2 is {} NOT-OK
type T3 = Unpack<PP>; //T3 is string OK
type T4 = Unpack<Cousin>; //T4 is {} NOT-OK
Expected behavior:
T1 to infer number
T2 to infer string
T3 to infer string
T4 to infer string
Actual behavior:
T1 infers number
T2 infers {}
T3 infers string
T4 infers {}
Workaround:
Uncomment foo, use the generic type in any form
Playground Link:
Playground Link
Related Issues:
TypeScript Version: 3.1.0-dev.20180831
Search Terms: infer, unused generic type
In below example infer behaves inconsistently when the generic type argument is unused.
It should either:
In real life scenario T is used to carry additional type info.
Code
Expected behavior:
T1 to infer number
T2 to infer string
T3 to infer string
T4 to infer string
Actual behavior:
T1 infers number
T2 infers {}
T3 infers string
T4 infers {}
Workaround:
Uncomment foo, use the generic type in any form
Playground Link:
Playground Link
Related Issues: