1. Can someone give a simple definition of what Record is?

A Record<K, T> is an object type whose property keys are K and whose property values are T. That is, keyof Record<K, T> is equivalent to K, and Record<K, T>[K] is (basically) equivalent to T.

  1. Is Record<K,T> merely a way of saying "all properties on this object will have type T"? Probably not all objects, since K has some purpose...

As you note, K has a purpose... to limit the property keys to particular values. If you want to accept all possible string-valued keys, you could do something like Record<string, T>, but the idiomatic way of doing that is to use an index signature like { [k: string]: T }.

  1. Does the K generic forbid additional keys on the object that are not K, or does it allow them and just indicate that their properties are not transformed to T?

It doesn't exactly "forbid" additional keys: after all, a value is generally allowed to have properties not explicitly mentioned in its type... but it wouldn't recognize that such properties exist:

declare const x: Record<"a", string>;
x.b; // error, Property 'b' does not exist on type 'Record<"a", string>'

and it would treat them as excess properties which are sometimes rejected:

declare function acceptR(x: Record<"a", string>): void;
acceptR({a: "hey", b: "you"}); // error, Object literal may only specify known properties

and sometimes accepted:

const y = {a: "hey", b: "you"};
acceptR(y); // okay
  1. With the given example:

     type ThreeStringProps = Record<'prop1' | 'prop2' | 'prop3', string>
    

    Is it exactly the same as this?:

     type ThreeStringProps = {prop1: string, prop2: string, prop3: string}
    

Yes!

Answer from jcalz on Stack Overflow
Top answer
1 of 4
721
  1. Can someone give a simple definition of what Record is?

A Record<K, T> is an object type whose property keys are K and whose property values are T. That is, keyof Record<K, T> is equivalent to K, and Record<K, T>[K] is (basically) equivalent to T.

  1. Is Record<K,T> merely a way of saying "all properties on this object will have type T"? Probably not all objects, since K has some purpose...

As you note, K has a purpose... to limit the property keys to particular values. If you want to accept all possible string-valued keys, you could do something like Record<string, T>, but the idiomatic way of doing that is to use an index signature like { [k: string]: T }.

  1. Does the K generic forbid additional keys on the object that are not K, or does it allow them and just indicate that their properties are not transformed to T?

It doesn't exactly "forbid" additional keys: after all, a value is generally allowed to have properties not explicitly mentioned in its type... but it wouldn't recognize that such properties exist:

declare const x: Record<"a", string>;
x.b; // error, Property 'b' does not exist on type 'Record<"a", string>'

and it would treat them as excess properties which are sometimes rejected:

declare function acceptR(x: Record<"a", string>): void;
acceptR({a: "hey", b: "you"}); // error, Object literal may only specify known properties

and sometimes accepted:

const y = {a: "hey", b: "you"};
acceptR(y); // okay
  1. With the given example:

     type ThreeStringProps = Record<'prop1' | 'prop2' | 'prop3', string>
    

    Is it exactly the same as this?:

     type ThreeStringProps = {prop1: string, prop2: string, prop3: string}
    

Yes!

2 of 4
334

A Record lets you create a new type from a Union. The values in the Union are used as attributes of the new type.

For example, say I have a Union like this:

type CatNames = "miffy" | "boris" | "mordred";

Now I want to create an object that contains information about all the cats, I can create a new type using the values in the CatNames union as keys.

type CatList = Record<CatNames, {age: number}>

If I want to satisfy this CatList, I must create an object like this:

const cats: CatList = {
  miffy: { age:99 },
  boris: { age:16 },
  mordred: { age:600 }
}

You get very strong type safety:

  • If I forget a cat, I get an error.
  • If I add a cat that's not allowed, I get an error.
  • If I later change CatNames, I get an error. This is especially useful because CatNames is likely imported from another file, and likely used in many places.

Real-world React example.

I used this recently to create a Status component. The component would receive a status prop, and then render an icon. I've simplified the code quite a lot here for illustrative purposes

I had a union like this:

type Statuses = "failed" | "complete";

I used this to create an object like this:

const icons: Record<
  Statuses,
  { iconType: IconTypes; iconColor: IconColors }
> = {
  failed: {
    iconType: "warning",
    iconColor: "red"
  },
  complete: {
    iconType: "check",
    iconColor: "green"
  };

I could then render by destructuring an element from the object into props, like so:

const Status = ({status}) => <Icon {...icons[status]} />

If the Statuses union is later extended or changed, I know my Status component will fail to compile and I'll get an error that I can fix immediately. This allows me to add additional error states to the app.

Note that the actual app had dozens of error states that were referenced in multiple places, so this type safety was extremely useful.

Docs

Wonderful to see that my silly little cat example is now part of the official TypeScript docs!

https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type

🌐
TypeScript
typescriptlang.org › docs › handbook › utility-types.html
TypeScript: Documentation - Utility Types
TypeScript provides several utility types to facilitate common type transformations.
🌐
Refine
refine.dev › home › blog › tutorials › typescript record type with examples
TypeScript Record Type with Examples | Refine
January 9, 2025 - The Record<> type is a TypeScript object transformation type that is often used to derive stable object types for API data in an application. This is possible mainly because the property identifiers of the Record<> type are themselves types ...
🌐
Mimo
mimo.org › glossary › typescript › record-type
TypeScript Record Type: Syntax, Use Cases, and Examples
The Record utility type in TypeScript is a built-in generic type that creates an object type with a fixed set of keys and a specified value type.
🌐
LogRocket
blog.logrocket.com › home › level up your typescript with record types
Level up your TypeScript with Record types - LogRocket Blog
April 9, 2025 - The Record<Keys, Type> is a utility type in TypeScript that helps define objects with specific key-value pairs. It creates an object type where the property keys are of type Keys, and the values are of type Type.
🌐
Geshan
geshan.com.np › blog › 2022 › 12 › typescript-record
A beginner’s guide to using TypeScript Record Type with examples
December 20, 2022 - In simple words, the Record type is a type available in TypeScript that can ensure consistency in implementing a dictionary (key-value pairs) with fixed values/type for Keys and a defined type for the values.
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › what-is-the-record-type-in-typescript
What is the Record Type in TypeScript ? - GeeksforGeeks
April 28, 2025 - In TypeScript, the Record type is a utility type that represents an object type with keys and values of a specific type. It is often used when you want to define a type for the keys and values of an object.
Find elsewhere
🌐
Graphite
graphite.com › guides › typescript-record-utility-type
The Typescript Record utility type - Graphite
A Record in TypeScript is a generic utility type that constructs an object type with a specific set of keys of a given type, and where all the values are of another specified type.
🌐
Convex
convex.dev › core concepts › maps, sets & specialized types › record
Record | TypeScript Guide by Convex
Record<K, V> is a utility type in TypeScript that helps enforce consistency by making sure that all key-value pairs in an object adhere to uniform types. This makes it easier to work with predictable data structures, especially when dealing ...
🌐
DEV Community
dev.to › kansoldev › how-i-discovered-typescripts-record-utility-type-and-how-it-solved-my-problem-40oc
How I Discovered TypeScript’s Record Utility Type (And How It Solved My Problem) - DEV Community
September 24, 2025 - Record is a built-in utility type in TypeScript. It's a cleaner way of specifying how the shape of an Object looks when we have keys and values that are predictable.
🌐
ITNEXT
itnext.io › use-typescript-record-types-for-better-code-ce1768c6cb53
Use TypeScript Record Types for Better Code | by Charles Chen | ITNEXT
January 12, 2023 - Using a Record, we can easily ensure that whenever new options are added, both the front-end and back-end correctly handle the new cases at dev/build time instead of runtime. Not only did we make the application easier to maintain thanks to TypeScript’s enforcement of exhaustive case handling, we’ve also shifted the flow of the code from procedural to structural; in other words, we use structure to dictate flow of control.
🌐
Thesoftwarelounge
thesoftwarelounge.com › typescript-record-type-guide
A Guide to The TypeScript Record Type - The Software Lounge
March 24, 2024 - At its core, the TypeScript Record type is a utility that enables developers to construct an Object type with a predefined set of keys and a uniform type for their values. The basic syntax of Record is Record<K, T>, where K represents the type ...
🌐
Medium
medium.com › @weidagang › having-fun-with-typescript-record-type-da765732a4cf
Having Fun with TypeScript: Record Type | by Dagang Wei | Medium
April 4, 2024 - Record Definition: The fruitColors object is defined as a Record<Fruit, Color>. This means its keys must be of type Fruit and its values of type Color. Valid vs. Invalid: The example shows how TypeScript will enforce the Fruit and Color types to prevent unexpected assignments.
🌐
Reddit
reddit.com › r/typescript › how to create record with optional string litteral keys?
r/typescript on Reddit: how to create Record with optional string litteral keys?
October 13, 2023 -

I am trying to create a Record type where I provide a union type of string litterals as key but rather than all the keys being required, I would like them to be optional

ie I would like baz0, baz1 and baz2 to all pass

type MyType = Record<"foo" | "bar", string>

const baz0: MyType = {
    foo: "hi"
} // Property 'bar' is missing in type '{ foo: string; }' but required in type 'Record<"foo" | "bar", string>'

const baz1: MyType = {
    bar: "bye"
} // Property 'foo' is missing in type '{ foo: string; }' but required in type 'Record<"foo" | "bar", string>'

const baz2: MyType = {
    foo: "hi",
    bar: "bye"
} // OK

anyone any suggestions?

🌐
SitePoint
sitepoint.com › blog › javascript › a comprehensive guide to understanding typescript record type
A Comprehensive Guide to Understanding TypeScript Record Type — SitePoint
August 27, 2024 - The Record type is a utility type that allows us to create an object type with specified keys and a uniform value type. This type is particularly useful for defining mappings and ensuring that all values in an object conform to a single type.
🌐
Sebastian De Deyne
sebastiandedeyne.com › typescript-record-type
The Record type in TypeScript | Sebastian De Deyne
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…
🌐
DEV Community
dev.to › mnathani › how-the-typescript-record-type-works-4c8
How the TypeScript Record Type Works - DEV Community
January 29, 2023 - The Record type in TypeScript is used to create a dictionary of key-value pairs, where the keys and values can have specific types.
🌐
HowToDoInJava
howtodoinjava.com › home › typescript › typescript record
TypeScript Record (with Examples)
September 1, 2023 - TypeScript Record is a utility type that creates an object type where the keys and the values associated with those keys are of the specified types.
🌐
Dmitri Pavlutin
dmitripavlutin.com › typescript-record
Record Type in TypeScript: A Quick Intro - Dmitri Pavlutin
May 7, 2023 - Record<K, V> is a generic type that represents an object type which keys are K and values are V.
🌐
DEV Community
dev.to › danywalls › how-to-use-record-type-in-typescript-1fml
How To Use Record Type In Typescript - DEV Community
August 14, 2023 - type ChampionshipRecord = Record<NBATeam, Championships>; This tells TypeScript that our ChampionshipRecord type is an object where every key is an NBATeam, and every value is a Championships (number).