Skip to content

Instantly share code, notes, and snippets.

@forivall
Created November 22, 2023 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forivall/545b35e8ad4d2bbf66af12f8666406de to your computer and use it in GitHub Desktop.
Save forivall/545b35e8ad4d2bbf66af12f8666406de to your computer and use it in GitHub Desktop.
// limit to 9 entries in the union, otherwise type instantiation gets very deep
export type ConstArrayOf<T, T2 = T> = [T] extends [never]
? []
: T extends infer U
? [U, ...ConstArrayOf<Exclude<T2, U>>]
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment