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

0

Issue

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.

Solution

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.

Answered By – Stéphane Veyret

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More