代码
提交代码
function pluck<T, K extends keyof T>(o: T, names: K[]): T[K][] { return names.map(n => o[n]) } interface Person { name: string position: string age: number } let person: Person = { name: 'Evan', position: 'Software Engineer', age: 27 } let values: unknown[] = pluck(person, ['name', 'age']) console.log(values)
运行结果