运行 ❯
获取你自己的
节点
服务器
×
更改方向
更改主题,深色/浅色
转至 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"