Skip to content

Instantly share code, notes, and snippets.

@AlexGeb
Created September 8, 2025 08:53
Show Gist options
  • Save AlexGeb/22a6eddf277ab166295568df229d03c4 to your computer and use it in GitHub Desktop.
Save AlexGeb/22a6eddf277ab166295568df229d03c4 to your computer and use it in GitHub Desktop.
/* eslint-disable @typescript-eslint/no-explicit-any */
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I,
) => void
? I
: never;
export type UnionToTuple<T, R extends any[] = []> = [T] extends [never]
? R
: UnionToIntersection<T extends any ? (t: T) => void : never> extends (
t: infer U,
) => void
? UnionToTuple<Exclude<T, U>, [...R, U]>
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment