我正在尝试键入一个函数,该函数返回一个通用对象数组的值数组(用于获取表的所有列值)。
class DataSource<T> {
constructor(private data: T[]) {}
public getColumnValues(column: keyof T): any[] { // this is the thing I don't know how to type!
return data.map(entry => entry[key]);
}
}
Run Code Online (Sandbox Code Playgroud)
目标是拥有一个显示正确返回值的通用签名。例如:getColumnValues('someDate') 应该是 Date[]或getColumnValues('someString')作为 string[]
我尝试搜索这个,但我可能无法正确表达我的问题......