Given I have an object like this:
const props = [
{ name: 'car', list: { brand: 'audi', model: 's4' }
{ name: 'motorcycle', list: { type: 'ktm', color: 'orange' }
] as constant;
I want to create a type that represents something like this:
type Props = {
car?: 'brand' | 'model',
motorcycle?: 'type' | 'color'
};
The closest I got was something like this:
type Props = Partial<Record<typeof props[number]['name'], typeof props[number]['list']>
But returns something like this:
type Props = {
car?: { brand: 'audi', model: 's4' } | { type: 'ktm' | color: 'orange' } | undefined,
motorcycle?: { brand: 'audi', model: 's4' } | { type: 'ktm' | color: 'orange' } | undefined
}
How can I achieve the desired result?