I am currently working on creating a function that will return an array of values from a generic object array, specifically designed for retrieving all column values from a table.
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]);
}
}
The main objective here is to establish a generic signature that accurately reflects the expected return value. For instance, getColumnValues('someDate')
should yield Date[]
, while getColumnValues('someString')
should result in string[]
.
Despite my efforts to find an answer, it seems like I may not have articulated my question effectively...