Skip to content

Instantly share code, notes, and snippets.

@fostyfost
Created June 3, 2024 20:21
Show Gist options
  • Save fostyfost/c90531ba670c395b905719129c28cd38 to your computer and use it in GitHub Desktop.
Save fostyfost/c90531ba670c395b905719129c28cd38 to your computer and use it in GitHub Desktop.
Union to tuple
export type UnionToTuple<U extends string, R extends any[] = []> = {
[S in U]: Exclude<U, S> extends never ? [...R, S] : UnionToTuple<Exclude<U, S>, [...R, S]>
}[U]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment