DEV Community

es404020
es404020

Posted on • Edited on

3 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more