TypeScript Version: 3.5.0-dev.20190514
Search Terms:
constrained generic inference infer keyword
infer open generic
infer constrained generic
Code
interfaceSynthetic<A,BextendsA>{}typeSyntheticDestination<T,U>=UextendsSynthetic<T, infer V> ? V : never;typeTestSynthetic=// Resolved to TSyntheticDestination<number,Synthetic<number,number>>;constw: TestSynthetic=undefined// ✓constx: TestSynthetic=null;// ✓consty: TestSynthetic=3;// Type '3' is not assignable to type 'T'.constz: TestSynthetic='3';// Type '"3""' is not assignable to type 'T'.Expected behavior:
- TestSynthetic resolved as number
- w, x, and z invalid with strict
- y valid
Actual behavior:
- TestSynthetic resolved as T -- an open generic from the underlying conditional type
- w and x valid, even with strict
- y and z error with commented errors
Playground Link:
https://bit.ly/30lTSqk
Related Issues:
#31326
Notes:
- Removing the
extends A constraint causes expected behavior, so that's likely involved somehow. - Turning on all strict options in typescript playground causes all four example cases to be errors -- unclear why this is stricter than
strict: true in my local tsconfig with @next. - I'm not 100% sure if a conditional type that resolves to an open generic is allowed -- I was certainly surprised to see it. If it is, this still seems to be a bug in conditional type resolution.
TypeScript Version: 3.5.0-dev.20190514
Search Terms:
constrained generic inference infer keyword
infer open generic
infer constrained generic
Code
Expected behavior:
Actual behavior:
Playground Link:
https://bit.ly/30lTSqk
Related Issues:
#31326
Notes:
extends Aconstraint causes expected behavior, so that's likely involved somehow.strict: truein my local tsconfig with @next.