Sebastian De Deyne

The Record type in TypeScript

∙ 1 min. read ∙ #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>;

More TypeScript

Vite with Laravel: Using TypeScript

When to add types and when to infer in TypeScript

Laravel Typescript Transformer