Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Created February 25, 2021 02:09
Show Gist options
  • Save hrdtbs/de0512f64d4d59cc36bf19e2bc29c04c to your computer and use it in GitHub Desktop.
Save hrdtbs/de0512f64d4d59cc36bf19e2bc29c04c to your computer and use it in GitHub Desktop.
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
type Tuplify<Union, Flag = [Union] extends [never] ? true : false, Last = LastOf<Union>> = true extends Flag
? []
: [...Tuplify<Exclude<Union, Last>>, Last]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment