DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

๐ŸŒš Friends don't let friends browse without dark mode.

Sorry, it's true.