Typescript: convert a tagged union into an union type
问题 I've the following tagged union interface interface Example { a: TypeA; b: TypeB; } as an output I would like to convert this tagged union into an union type such as: type oneOf<T> = ... Where var example: oneOf(Example); // would be { a: TypeA } | { b : TypeB } I have not been able to map the type keys into an object having only the key as parameter. Any idea ? 回答1: You can do it with a combination of: Distributive conditional types Mapped types interface Example { a: string; b: number; }