Reading List
The Record type in TypeScript from Sebastian De Deyne RSS feed.
The Record type in TypeScript
I can’t count the amount of times I’ve defined an object type with unknown string keys and a specific value type.
type Scores = {
[key: string]: number;
}
And despite using it all the time, I can’t for the life of me remember the [key: string]
syntax.
Today, my problems are solved. Apparently TypeScript has a built in Record
type that does exactly that:
type Scores = Record<string, number>;