I've been using a ReadonlyDate type in my projects. It looks like this:
export type ReadonlyDate = Readonly<
OmitStrict<
Date,
| "setTime"
| "setMilliseconds"
| "setUTCMilliseconds"
| "setSeconds"
| "setUTCSeconds"
| "setMinutes"
| "setUTCMinutes"
| "setHours"
| "setUTCHours"
| "setDate"
| "setUTCDate"
| "setMonth"
| "setUTCMonth"
| "setFullYear"
| "setUTCFullYear"
>
>;
It's philosophically similar to the built in ReadonlyArray, ReadonlySet, etc.
It would be great if date-fns functions could at least accept (if not return) this type. That way an entire project could use readonly dates similarly to readonly arrays. This would give an (almost) immutability guarantee.
Returning this type would be a more drastic (and breaking) change, so probably not worth considering.
I've been using a
ReadonlyDatetype in my projects. It looks like this:It's philosophically similar to the built in
ReadonlyArray,ReadonlySet, etc.It would be great if date-fns functions could at least accept (if not return) this type. That way an entire project could use readonly dates similarly to readonly arrays. This would give an (almost) immutability guarantee.
Returning this type would be a more drastic (and breaking) change, so probably not worth considering.