I'm trying to build a generic type (Response) that will be an object containing all values from KeysForResponse, which is the values from the valueIWant property for each object in MyObject[]. I can't seem to figure it out, or if its even possible. Basically, if I pass the following array into a function:
[{valueIWant: 'makeMeAKey', foo: 'bar'}, {valueIWant: 'alsoMakeMeAKey', foo: 'bar'}]
I want to return the following type:
{makeMeAkey: string, alsoMakeMeAKey: string}
Here is what I currently have, which isn't generic
interface MyObject {
valueIWant: string;
nonImportantValue: string;
}
type KeysForResponse = Array<MyObject>[number]['valueIWant'];
type Response = {
[K in KeysForResponse]: string;
};
fooproperty in the array for? How are you using the function?stringnotfoo