I have a type like this:
type Popups = {
'createUserDialog': TCreateUserDialogProperties,
'updateUserDialog': TUpdateUserDialogProperties
};
I would like to convert this type to:
type Something = {
name: 'createUserDialog',
properties: TCreateUserDialogProperties
} | {
name: 'updateUserDialog',
properties: TUpdateUserDialogProperties
};
How I can do this, I've tried this solution:
type Something = {
[K in keyof Popups]: {
name: K,
properties: Popups[K]
}
};
but it is incorrect...
CodePudding user response:
You've pretty much got it. I think this is what you want:
type Something = {
[K in keyof Popups]: {
name: K,
properties: Popups[K]
}
}[keyof Popups];