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
Moments are not immutable. Maybe they will be some day (moment/moment-rfcs#2), but for now it doesn't look like this will be pushed through soon.
To provide a temporary solution for this, I propose to split the TypeScript definition of a Moment into two interfaces: MomentReadonly (extending Object) and Moment (extending MomentReadonly). All pure methods can then be moved to the MomentReadonly class. An object with this interface will still be the fully mutable moment, but the functionality will be limited to only pure methods by the compiler.
This is comparable to the ReadonlyArray<T> interface, which also provides somewhat of a compile-time readonly access to a regular mutable array. For more information about this, please see https://basarat.gitbooks.io/typescript/docs/types/readonly.html, especially "Difference from const", example 2.
In case you are open to this change, but do not have time to do this, I can create a pull request for this.
Kind regards,
Martijn Verbakel
The text was updated successfully, but these errors were encountered:
Hello,
Moments are not immutable. Maybe they will be some day (moment/moment-rfcs#2), but for now it doesn't look like this will be pushed through soon.
To provide a temporary solution for this, I propose to split the TypeScript definition of a Moment into two interfaces:
MomentReadonly
(extendingObject
) andMoment
(extendingMomentReadonly
). All pure methods can then be moved to theMomentReadonly
class. An object with this interface will still be the fully mutable moment, but the functionality will be limited to only pure methods by the compiler.This is comparable to the
ReadonlyArray<T>
interface, which also provides somewhat of a compile-time readonly access to a regular mutable array. For more information about this, please see https://basarat.gitbooks.io/typescript/docs/types/readonly.html, especially "Difference fromconst
", example 2.In case you are open to this change, but do not have time to do this, I can create a pull request for this.
Kind regards,
Martijn Verbakel
The text was updated successfully, but these errors were encountered: