DEV Community

es404020
es404020

Posted on • Updated on

Typescript Utility Readonly

Readonly

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


interface Todo {
  title: string;
}

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

todo.title = "Hello";

Enter fullscreen mode Exit fullscreen mode

Assigning a title to Todo Interface would throw an error .

Released:2.1

Reference: Official typescript docs

Top comments (0)