79432417

Date: 2025-02-12 08:50:50
Score: 1
Natty:
Report link

You can make use of the Readonly<Type> utility type.

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

When trying to modify todo in the last line, a typ error occurs:

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

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Korbinian Hutter