Skip to content

[feature request] readonly typescript interface #4169

Description

@mhverbakel

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions