Reputation: 11480
How can I create a type DESIRED_RESULT
starting from INITIAL
.
from:
export type INITIAL = {
aa: boolean,
bb: string,
cc: number[],
};
to:
export type DESIRED_RESULT =
{ aa: boolean } |
{ bb: string } |
{ cc: number[] };
Upvotes: 1
Views: 400
Reputation: 214949
utility-types has Unionize
that does exactly that:
export type Unionize<T extends object> = {
[P in keyof T]: { [Q in P]: T[P] }
}[keyof T];
type DESIRED_RESULT = Unionize<INITIAL>
Upvotes: 2