I have been attempting to create a generic type (Response) that consolidates all values from KeysForResponse, specifically the values from the valueIWant
property for each object in MyObject[]. I am struggling to find a solution and wondering if it is even feasible. Essentially, when I input the following array into a function:
[{valueIWant: 'makeMeAKey', foo: 'bar'}, {valueIWant: 'alsoMakeMeAKey', foo: 'bar'}]
I expect to receive the following type as output:
{makeMeAkey: string, alsoMakeMeAKey: string}
This is what I currently have, which lacks generality:
interface MyObject {
valueIWant: string;
nonImportantValue: string;
}
type KeysForResponse = Array<MyObject>[number]['valueIWant'];
type Response = {
[K in KeysForResponse]: string;
};