Given the interface
interface FormField {
name: string;
}
and a value such as:
const fields: FormField[] = [
{ name: 'givenName' },
{ name: 'familyName' }
]
I would like to infer this interface:
interface FormModel {
givenName: string;
familyName: string;
}
So use the array's property values as property names.
I tried something like:
type Model<T extends Array<FormField>> = { [K['name'] in T]: string };
but this doesn't work. Is this kind of thing possible in Typescript?