TypeScript Utility Types
Record<K, T> — keyed value contracts
Record constructs an object type whose keys come from K and whose property values share T. A finite literal-key union requires each listed key; a broad string key type describes an index signature, not a guarantee that every runtime key exists. Record is useful for lookup tables and handler maps, but it does not allocate keys or create a Map. Example output: "Ready". Verified with strict TypeScript 5.8.3, ES2022 and Node.js 22.16.0. This utility affects static typing; no runtime validation or transformation is supplied by the type itself.
Formal Syntax & Structure
typescript syntaxtypescript
Record<K, T>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| K | K extends keyof any | Property-key type: string, number, symbol or their subtypes. |
| T | type parameter | Value type associated with each key. |
Working Example
Example Snippettypescript
type State = "queued" | "done";const labels: Record<State, string> = { queued: "Waiting", done: "Ready" };console.log(labels.done);