What is the Record Type in TypeScript ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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. In this article, we will learn what is the Record type in TypeScript. Syntax:Record<Keys, Type>Keys: A union of string literal types representing the keys of the record.Type: The type that the values associated with the keys should have.Example: In this example, Car is a type that represents an object with keys 'make', 'model', and 'year', and each key must have a string value. JavaScript type Car = Record<string, string | string | number>; const myCar: Car = { make: 'Toyota', model: 'Camry', year: 2022, }; console.log(typeof myCar.make, typeof myCar.model, typeof myCar.year); Output: string string numberUse CasesUser ProfileImagine you are developing a user management system, and you want to define the structure of a user profile. The user profile has specific properties such as 'username', 'email', and 'age'. By using the Record type, you can ensure that instances of the user profile always have the expected properties with the correct data types. Example: The below code example explains the use of the Record type in case of creating a user profile. JavaScript type UserProfile = Record<'username' | 'email' | 'age', string | number>; const validUserProfile: UserProfile = { username: 'john_doe', email: '[email protected]', age: 25, }; console.log(typeof validUserProfile.username, typeof validUserProfile.email, typeof validUserProfile.age) Output: string string numberFeature FlagsConsider a web application where you want to manage feature flags dynamically. Feature flags are configuration settings that control the availability of certain features. Using the Record type, you can create a type that represents a set of feature flags with string keys and boolean values. Example: In this use case, the FeatureFlags type allows you to create a flexible configuration object for feature flags. JavaScript type FeatureFlags = Record<string, boolean>; const featureFlags: FeatureFlags = { enableNotifications: false, darkMode: true, // ... additional feature flags }; console.log(featureFlags); Output: { "enableNotifications": false, "darkMode": true // ... additional feature flags} Comment More infoAdvertise with us Next Article What is the Record Type in TypeScript ? A amanv09 Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads What is Type Predicates in Typescript ? In this article, we are going to learn about the type predicates in Typescript. TypeScript is a statically typed programming language that provides many features to make your code more efficient and robust. Type predicates in TypeScript are functions that return a boolean value and are used to narro 3 min read What is the Function type in TypeScript ? TypeScript is a JavaScript-based programming language with a typed syntax. It provides improved tools of any size. It adds extra syntax to JavaScript. This helps in facilitating a stronger interaction between you and your editor. It also helps in catching the mistakes well in advance. It uses type 3 min read What are intersection types in Typescript ? In Typescript, Although intersection and union types are similar, they are employed in completely different ways. An intersection type is a type that merges several kinds into one. This allows you to combine many types to create a single type with all of the properties that you require. An object of 3 min read What is Type Erasure in TypeScript? TypeScript is a very mighty superset of JavaScript, which adds static typing to the language and allows developers to catch errors early on as well as write more maintainable code. This being said a TypeScript type system erases type information at compile time (or during the compilation), a phenome 4 min read What are template literal types in Typescript ? Template literal types in TypeScript allow the construction of new string literal types by combining existing string literal types using template literal syntax.They enable the creation of complex string patterns by embedding unions and other literal types within template literals.This feature enhan 3 min read Typescript Record<Keys, Type> Utility Type In this article, we are going to learn about the Record<Keys, Type> in Typescript. TypeScript is a programming language that is a strict syntactical superset of JavaScript. It adds optional static typing and class-based object-oriented programming to JavaScript, one of the features is Record 4 min read What are Hybrid Types in TypeScript? Hybrid types are used by TypeScript to refer to types that combine different things such as objects, functions, arrays etc. In this article, we will learn more about Hybrid Types in TypeScript.What are Hybrid Types in TypeScript?In TypeScript, using interfaces or type aliases we can define hybrid ty 2 min read What are string literal types in TypeScript ? The string literal type was added in TypeScript version 1.8. String literal types work well with union types and type aliases in practice. These properties can be combined to give strings enum-like functionality. The string literal type allows you to specify a set of possible string values for a var 3 min read Higher-Order Types in TypeScript Higher-order types are among the advanced aspects of Typescript that give priority to types as first-class citizens, similar to higher-order functions of JavaScript that accept a function as an argument or return a function, higher-order types can accept types or return types.These are the following 6 min read What is Type Annotations in TypeScript ? TypeScript Type Annotations allow developers to explicitly define the types of variables, functions, and other elements in the program.They help catch mistakes early by ensuring the right data type is used.They make the code easier to understand and follow.Type Annotations help avoid errors and make 3 min read Like