Last active
January 24, 2025 01:04
-
-
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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