readonly properties can only be assigned in a class constructor or at the point of declaration. If a class has a property that's not
marked readonly but is only set in the constructor, it could cause confusion about the property's intended use. To avoid confusion, such
properties should be marked readonly to make their intended use explicit, and to prevent future maintainers from inadvertently changing
their use.
class Person {
private _birthYear: number; // Noncompliant
constructor(birthYear: number) {
this._birthYear = birthYear;
}
}
class Person {
private readonly _birthYear: number; // Noncompliant
constructor(birthYear: number) {
this._birthYear = birthYear;
}
}