如何从DESIRED_RESULT
开始创建类型INITIAL
。
来自:
export type INITIAL = {
aa: boolean,
bb: string,
cc: number[],
};
收件人:
export type DESIRED_RESULT =
{ aa: boolean } |
{ bb: string } |
{ cc: number[] };
答案 0 :(得分:2)
utility-types的Unionize
可以做到:
export type Unionize<T extends object> = {
[P in keyof T]: { [Q in P]: T[P] }
}[keyof T];
type DESIRED_RESULT = Unionize<INITIAL>