Skip to content

Instantly share code, notes, and snippets.

@ryangoree
Last active January 24, 2025 01:04
Show Gist options
  • Save ryangoree/8c357c5d00cc924fecf48036545fbba8 to your computer and use it in GitHub Desktop.
Save ryangoree/8c357c5d00cc924fecf48036545fbba8 to your computer and use it in GitHub Desktop.
Get a tuple type with a length of `TCount` where each element is of type `T`.
/**
* Get a tuple type with a length of `TCount` where each element is of type `T`.
*
* @example
* ```ts
* type ThreeTuple = Tuple<string, 3>;
* // [string, string, string]
* ```
*/
export type Tuple<T = any, TCount extends number = number> = (
| []
| [T, ...T[]]
) &
(number extends TCount
? {}
: {
length: TCount;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment