UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

21 lines (18 loc) • 596 B
import type { Args, Fn } from "../HKT"; /** * Convert a union type to an intersection type. * * Sig: `<T>(u: UnionOf<T>) => IntersectOf<T>` */ export type ToIntersection<U> = (U extends unknown ? (_: U) => void : never) extends (mergedIntersection: infer I) => void ? I & U // The `& U` is to allow indexing by the resulting type : never; /** * [Fn] Convert a union type to an intersection type. * * Sig: `<T>(u: UnionOf<T>) => IntersectOf<T>` */ export default interface ToIntersectionFn extends Fn<[unknown], unknown> { def: ([u]: Args<this>) => ToIntersection<typeof u>; }