Home > OS >  What "signal intent " actually means for TypeScript's read-only properties?
What "signal intent " actually means for TypeScript's read-only properties?

Time:11-22

I'm reading chapter: object of the TypeScript Handbook. And it said:

It’s important to manage expectations of what readonly implies. It’s useful to signal intent during development time for TypeScript on how an object should be used. TypeScript doesn’t factor in whether properties on two types are readonly when checking whether those types are compatible, so readonly properties can also change via aliasing.

By saying "It’s important to manage expectations of what readonly implies. It’s useful to signal intent during development time for TypeScript on how an object should be used", what does it actually mean? I can figure out this is about the advantage of using readonly, but I still don't quite understand that.

CodePudding user response:

The purpose of the readonly property is to signal to other developers your intent to make that property read-only. But there are easy workarounds to write to that property anyway.

  • Related