Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
interface Person { name: string; age: number; } // `keyof Person` here creates a union type of "name" and "age", other strings will not be allowed function printPersonProperty(person: Person, property: keyof Person) { console.log(`Printing person property ${property}: "${person[property]}"`); } let person = { name: "Max", age: 27 }; printPersonProperty(person, "name"); // Printing person property name: "Max"s
Printing person property name: "Max"