Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

UnionToIntersection

Given a union type U = T1 | T2 | ..., returns an intersected type (T1 & T2 & ...).

Uses distributive conditional types and inference from conditional types. This works because multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred. https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type

type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

§Type Parameters

§Type

§
(U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never
[src]