Skip to content

Instantly share code, notes, and snippets.

@Roaders
Last active February 21, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roaders/5e61dbbb38c050fdc00645de4f18af4b to your computer and use it in GitHub Desktop.
Save Roaders/5e61dbbb38c050fdc00645de4f18af4b to your computer and use it in GitHub Desktop.
An example of how to map a Tuple to a record.
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