Last active
February 21, 2021 15:00
-
-
Save Roaders/5e61dbbb38c050fdc00645de4f18af4b to your computer and use it in GitHub Desktop.
An example of how to map a Tuple to a record.
This file contains 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
type Tuple = [ | |
{name: "one", type?: number}, | |
{name: "two", type: number}, | |
{name: "three", type: number[]} | |
]; | |
type RecordFromTuple = { | |
[P in Tuple[number] as P["name"]]: P["type"] | |
} | |
const record: RecordFromTuple = { | |
one: undefined, | |
two: 6, | |
three: [7] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment