TypeScript Version: 2.7.0-dev.20180123
Search Terms: indexed access, non null assertion, type parameter
Code
// --strictNullChecks enabledinterfaceI{foo?: string;bar?: string;}declarefunctiontake<T>(p: T): void;functionfails<KextendskeyofI>(o: I,k: K){take<string|undefined>(o[k]);// workstake<string>(o[k]!);// Argument of type 'I[K]' is not assignable to parameter of type 'string'. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.}// If the key is not generic, everything works as expectedfunctionworks<TextendsI>(o: T,k: keyofI){take<string>(o[k]!);// no error here, which should stay that way}Expected behavior:
No error as this worked very well in typescript@2.7.0-rc
Actual behavior:
Error as stated in the inline comment.
Playground Link:
Related Issues:
Another recent change to IndexedAccess inference: #21368
TypeScript Version: 2.7.0-dev.20180123
Search Terms: indexed access, non null assertion, type parameter
Code
Expected behavior:
No error as this worked very well in
typescript@2.7.0-rcActual behavior:
Error as stated in the inline comment.
Playground Link:
Related Issues:
Another recent change to IndexedAccess inference: #21368