-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Compiler throwing error "Cannot assign to 'calendarFormat' because it is a read-only property" #5348
Comments
@HARIKSREEE See issue #5444 . You can try the following code. import * as moment from 'moment';
moment.default.calendarFormat = function (myMoment: any, now: any): string {
return ''
} or import moment from 'moment';
moment.calendarFormat = function (myMoment: any, now: any): string {
return ''
} |
Please re-open if you still have issues. |
This was referenced May 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
While setting the moment.calendarFormat function, typescript compiler throwing "error TS2540: Cannot assign to 'calendarFormat' because it is a read-only property."
Code used
moment.calendarFormat = function(myMoment) { const diff = myMoment.diff(moment(Date()), 'minutes', true) * -1; const retVal = diff < 30 ? 'now' : diff < 1440 ? 'sameDay' : diff < 2880 ? 'lastDay' : 'sameElse'; return retVal; };
Expected behavior
The compiler should not throw any error while assigning the function
Environment
typescript: 3.5.3
moment: 2.24.0
*Locale used
en-gb
The text was updated successfully, but these errors were encountered: