Convert a Tuple to a Union Type

TypeScript lets you create a union type from a tuple type. That's useful when you want to make a type that's a union of multiple types.

ts
1type UnionFromTuple<Tuple extends readonly (string | number | boolean)[]> =
2 Tuple[number];
3
4const animals = ['🐶', '🙀', '🐮'] as const;
5
6type Animal = UnionFromTuple<typeof animals>;
7
8// type Animal = '🐶' | '🙀' | '🐮';