Last active
January 20, 2025 23:17
-
-
Save ryangoree/eec579fdf6cdb79220c7206b0232e768 to your computer and use it in GitHub Desktop.
ByIndex
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
| /** | |
| * Converts array or tuple `T` to an object keyed by index. | |
| * | |
| * Example: | |
| * type ExampleTuple = ByIndex<[string, number]>; // { 0: string, 1: number } | |
| * type ExampleArray = ByIndex<(string | number)[]>; // { [x: number]: string | number } | |
| */ | |
| type ByIndex<T extends any[]> = { | |
| [K in Extract<keyof T, `${number}`>]: T[K]; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment