UnionToIntersection
@tsed/schema
Usage
typescript
import { UnionToIntersection } from "@tsed/specs/schema/src/domain/types";Overview
ts
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;Description
Converts a union type to an intersection type.
This advanced TypeScript utility transforms a union of types (A | B | C) into an intersection of types (A & B & C), which is useful for schema composition and merging operations.
Usage
typescript
type Union = { a: string } | { b: number };
type Intersection = UnionToIntersection<Union>;
// Result: { a: string } & { b: number }