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 we are trying to subclass from generated class we need to quite literally overwrite all modifying objects. To illustrate, I'll take your example from readme (with some minor modifications, such as _data having protected modifier instead of private):
exportclassCircle{// snipped for brevityprotected_data: any;constructor(data: any={}){this._data=data;}getuuid(): string{returnthis._data.uuid;}setUuid(uuid: string): Circle{constdata=this._data.uuid=uuid;returnnewCircle(data);}// More snipping}
If we are to subclass from this object, say like this
Then trying to use this in the following piece of code will lead to type error:
letother: OtherCircle=newOtherCircle();other=other.setUuid('bar');// triggers TSError with message "Type 'Circle' is not assignable to type 'OtherCircle'."
Very often however we'll use const modifiers, which will mask the issue and lead to very nasty bugs later on:
On the other hand, we could also make a drastic step and simply switch all our generated objects to be http://facebook.github.io/immutable-js/docs/#/Record This would most definitely require tons more work though and is definitely a breaking change.
If we are trying to subclass from generated class we need to quite literally overwrite all modifying objects. To illustrate, I'll take your example from readme (with some minor modifications, such as
_data
havingprotected
modifier instead ofprivate
):If we are to subclass from this object, say like this
Then trying to use this in the following piece of code will lead to type error:
Very often however we'll use
const
modifiers, which will mask the issue and lead to very nasty bugs later on:I hope this explains what the issue is.
The text was updated successfully, but these errors were encountered: