0Pricing
TypeScript Academy · Lesson

Index Signatures vs Record

Choose between index signatures and the Record utility type.

Two Ways to Type a Map

TypeScript offers two common ways to describe a dictionary: an index signature like { [k: string]: V }, and the built-in utility type Record<K, V>. They overlap heavily but read differently.

The Record Utility Type

Record<K, V> constructs an object type whose keys are K and whose values are V. With string as the key, it is equivalent to a string index signature.

type Scores = Record<string, number>
const game: Scores = { alice: 10, bob: 7 }
console.log(game.alice)

All lessons in this course

  1. Defining Index Signatures
  2. String vs Number Index Signatures
  3. Combining Known and Dynamic Keys
  4. Index Signatures vs Record
← Back to TypeScript Academy