Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] readonly typescript interface #4169

Open
mhverbakel opened this issue Sep 11, 2017 · 0 comments · May be fixed by #5752
Open

[feature request] readonly typescript interface #4169

mhverbakel opened this issue Sep 11, 2017 · 0 comments · May be fixed by #5752

Comments

@mhverbakel
Copy link

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 (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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants