TypeScript Readonly <Type> Utility Type Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we are going to learn about Readonly<Type> Utility Type in Typescript. Typescript is a popular programming language used for building scalable and robust applications. One of the features of Typescript is Readonly<Type> Utility Type which is used to create a new type where all properties are readonly, meaning they cannot be modified once assigned a value. Syntax interface GFG { name: string; age: number;}const g: Readonly<GFG> = { name: 'John', age: 30};Example 1: In this example, we will see how to make a variable Readonly. JavaScript /* Define an interface Person with three properties: name, age, and address */ interface Person { name: string; age: number; } /* Declare a Readonly constant called person with the Person type and assign it a value of { name: 'John', age: 30 } */ const person: Readonly<Person> = { name: 'John', age: 30 }; /* Log the person constant to the console to see the output */ console.log(person); Output: Example 2: In this example, we will try to change the readonly property of our object. We will get an error. JavaScript /* Define an interface Person with three properties: name, age, and address */ interface Person { name: string; age: number; } /* Declare a Readonly constant called person with the Person type and assign it a value of { name: 'John', age: 30 } */ const person: Readonly<Person> = { name: 'John', age: 30 }; /* Log the person constant to the console to see the output */ person.name='Akshit'; console.log(person); Output: Reference: https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype Comment More infoAdvertise with us Next Article TypeScript Readonly <Type> Utility Type N nikitamehrotra99 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 TypeScript-Reference +2 More Similar Reads TypeScript NonNullable<Type> Utility Type In this article, we are going to learn about NonNullable<Type> Utility Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, the NonNullable<Type> utility is used to create a new type by removing null and undef 2 min read TypeScript Object readonly Tuple Types In this article, we will learn about Object readonly Tuple Types in Typescript. In TypeScript, an object with read-only tuple types is a type that represents an object with properties where each property has a specific value and the order of properties is fixed, just like a tuple. However, unlike re 3 min read TypeScript Object The ReadonlyArray Type In this article, we are going to learn about Object The ReadonlyArray Type in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, the ReadonlyArray<T> type is used to create an immutable (read-only) array of elements of ty 3 min read Different ways to Create a TypeScript Mapped Type Utility Type Mapped types in TypeScript are a powerful and flexible feature that allows developers to create new types by transforming existing ones. These types enable you to iterate through the keys of an object type and construct a new type based on the original type's keys and values. This feature is particu 5 min read TypeScript Utility Types TypeScript utility types are predefined constructs that facilitate common type transformations, enhancing code flexibility and maintainability. They allow developers to modify existing types easily, such as by making properties optional or read-only.Utility types help in creating more expressive and 5 min read TypeScript Object Type readonly Properties In TypeScript, the readonly modifier ensures that a property can be assigned a value only once during initialization and cannot be changed thereafter.This immutability helps prevent accidental modifications to object properties, enhancing code reliability.You can apply readonly to properties in clas 3 min read How to Create Deep Readonly Type in Typescript? In TypeScript, the readonly access modifier is a powerful tool that ensures immutability by marking properties of a class as immutable. Once a property is markedreadonly, it cannot be reassigned. This is highly useful for maintaining consistent and safe data structures, especially in scenarios such 3 min read What is the Record Type in TypeScript ? 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, 2 min read What is readonly in Typescript ? This article will cover the readonly keyword in TypeScript, which is a powerful superset of JavaScript that adds extra features and syntax to the language. The readonly keyword is one of these features, used to set a property or variable as read-only, meaning that the value cannot be changed once it 3 min read TypeScript Optional Properties Type TypeScript Opional properties type provides a way of defining the parts that are not necessarily required.TypeScript Optional Properties TypesOptional Properties are properties that are not required mandatorily and can be omitted when not needed.In TypeScript, you can define optional properties in a 6 min read Like