Open this example in the interactive library
Source code
const words = ["build", "ship", "test"];
console.log(
(<T, K extends keyof T>(obj: T, key: K): T[K] => obj[key])(
{ name: "Ada", rank: 2 },
"rank",
),
);
Sample output
2

Open this example in the interactive library
const words = ["build", "ship", "test"];
console.log(
(<T, K extends keyof T>(obj: T, key: K): T[K] => obj[key])(
{ name: "Ada", rank: 2 },
"rank",
),
);
2