What is the purpose of the Record type in TypeScript?

I’ve come across Record<K, T> in TypeScript and want to understand how it works. Is Record<'a' | 'b', string> just a shorthand for defining an object with specific keys and uniform value types?

Also, does it restrict other keys outside K?

Looking for clarity on how the typescript record type behaves and how it differs from writing an object type manually.

Yeah, exactly, Record<'a' | 'b', string> is basically a shortcut to say: I want an object with keys ‘a’ and ‘b’, and all values should be strings.

I use it when creating config maps or translation tables:

const labels: Record<'home' | 'about', string> = {
  home: 'Home Page',
  about: 'About Us',
};

It’s cleaner than writing the full object type manually.

What I like about Record<K, T> is that it’s restrictive. You can’t add keys outside of K unless you explicitly allow them.

So if I do:


type MyKeys = 'foo' | 'bar';
const data: Record<MyKeys, number> = {
  foo: 1,
  bar: 2,
  // baz: 3, // ❌ TypeScript will yell at this
};

This helps enforce strict typings across shared data objects in larger codebases.

To me, Record is super useful when I want to dynamically create types. I even use it with enums or unions:

enum Status {
  SUCCESS = 'success',
  FAIL = 'fail',
}
type Result = Record<Status, string>;

It saves time and scales well when you don’t want to write out every property manually.

And yes, it prevents extra keys unless you extend it with an index signature.