UnionToIntersectiontype
Helper type to turn a union type into an intersection type.
(U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never
Advanced TypeScript utility types used internally across Shelving. Import these when you need to manipulate generic type algebra in your own code.
UnionToIntersection<U>Converts a union type into an intersection type.
import type { UnionToIntersection } from "shelving/util";
type A = { a: string };
type B = { b: number };
type AB = UnionToIntersection<A | B>; // { a: string } & { b: number }Resolve<T>Flattens an intersection of object types into a single readable object type. Useful for making hover tooltips and error messages readable.
import type { Resolve } from "shelving/util";
type Merged = Resolve<{ a: string } & { b: number }>;
// { a: string; b: number }Helper type to turn a union type into an intersection type.
(U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never
Helper type to resolve and normalise an object.
{ [K in keyof T]: T[K] }