Typescript Readonly utility

es404020 - Sep 5 '21 - - Dev Community

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player