Closed
Description
TypeScript Version: 3.1.0-dev.20180810
Code
const f = <T extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) =>
{
const s: string = t[k];
};
Expected behavior: Successful compilation
Actual behavior: I get the following error:
error TS2322: Type 'T[K]' is not assignable to type 'string'.
const s: string = t[k];
~
Playground Link: Link
Additional Notes: This compiles successfully (link):
const f = <T extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) =>
{
const s: string = t['cool'];
};
as does this (link):
const f = <T extends { [K0 in K]: string; }, K extends keyof T>(t: T, k: K) =>
{
const s: string = t[k];
};