Skip to content

Instantly share code, notes, and snippets.

@andrekovac
Created July 20, 2022 12:43
Show Gist options
  • Save andrekovac/c1062182381554cecd80fb9602d40647 to your computer and use it in GitHub Desktop.
Save andrekovac/c1062182381554cecd80fb9602d40647 to your computer and use it in GitHub Desktop.
Two ways to create a a TupleToUnion type in TypeScript
/**
* Two ways to create a a TupleToUnion type in TypeScript
*/
export type TupleToUnion<T extends unknown[]> = T[number];
export type TupleToUnion2<T extends unknown[]> = T extends [
infer U,
...infer Rest
]
? TupleToUnion2<Rest> | U
: never;
@andrekovac
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment