TypeScript Version: 2.7.0-dev.20180123
Search Terms: indexed access, type parameter keyof
Code
interfaceI{foo: string;}declarefunctiontake<T>(p: T): void;functionfn<TextendsI,KextendskeyofT>(o: T,k: K){take<string>(o[k]);// Argument of type 'T[K]' is not assignable to parameter of type 'string'.take<{}|null|undefined>(o[k]);// Type 'T[K]' is not assignable to type '{} | null | undefined'. Type 'T[K]' is not assignable to type '{}'.take<any>(o[k]);// this one works}Expected behavior:
Compiles without error. 2.7.0-rc allows all of the above, although the type of the indexed access is not correctly inferred, see #12991 (comment)
Actual behavior:
Error on the first two calls, see inline comments.
Playground Link:
Related Issues:
#12991
TypeScript Version: 2.7.0-dev.20180123
Search Terms: indexed access, type parameter keyof
Code
Expected behavior:
Compiles without error. 2.7.0-rc allows all of the above, although the type of the indexed access is not correctly inferred, see #12991 (comment)
Actual behavior:
Error on the first two calls, see inline comments.
Playground Link:
Related Issues:
#12991