/** * 联合类型转交叉类型 * @see https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type/50375286#50375286 * @see https://github.com/Microsoft/TypeScript/pull/21496 * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types * @example * 输入: * type example = UnionToIntersection<{ name: string } | { age: number } | { visible: boolean }> * 输出: * type example = { name: string } & { age: number } & { visible: boolean } */ export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;