You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you create a "property" with a public getter and no setter. if you then try to set that property typescript doesn't tell you this isn't allowed. But it sure will blow up your code.
private _date: Date;
public get Date()
{
return this._date;
}
In the above scenario if you do
this.Date = new Date();
typescript allows this without catching anything (no red underbar or error), but the javascript doesn't allow it. Changing the code to the below code works as expected.
this._date = new Date();
The text was updated successfully, but these errors were encountered:
The other is talking about readonly properties in interfaces (something that the current language does not support). This one is talking about a simple validation to throw a compiler error when trying to change a getter only property.
This one is very simple to implement, totally different from the other.
Both are very important, but for me, this one is a must.
"Property without a setter" and "Property that is read-only" is a distinction without a difference.
For example, if we have some class
classFoo{getbar(){return0}}
This is its corresponding .d.ts:
classFoo{bar: number;}
Without a readonly modifier, there's no way to represent this except when we can see the implementation. Trying to implement this as via "see if there's a setter" would be a hack.
if you create a "property" with a public getter and no setter. if you then try to set that property typescript doesn't tell you this isn't allowed. But it sure will blow up your code.
In the above scenario if you do
this.Date = new Date();
typescript allows this without catching anything (no red underbar or error), but the javascript doesn't allow it. Changing the code to the below code works as expected.
this._date = new Date();
The text was updated successfully, but these errors were encountered: