keyof example

Run Settings
LanguageTypeScript
Language Version
Run Command
function getProperty<T, K extends keyof T>(obj: T, key: K) { return obj[key]; // Inferred type is T[K] } function setProperty<T, K extends keyof T>(obj: T, key: K, value: T[K]) { obj[key] = value; } let x = { foo: 10, bar: "hello!" }; let foo = getProperty(x, "foo"); // 10 console.log(foo);
Editor Settings
Theme
Key bindings
Full width
Lines