DEV Community

es404020
es404020

Posted on

Typescript Readonly utility

Readonly

Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned.

Example

interface Todo {
  title: string;
}

const todo: Readonly<Todo> = {
  title: "Delete inactive users",
};

todo.title = "Hello";
Enter fullscreen mode Exit fullscreen mode

Cannot assign to 'title' because it is a read-only property.

Released:
2.1
Refencence: Typescript offical documentation

Top comments (0)