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

Compiler throwing error "Cannot assign to 'calendarFormat' because it is a read-only property" #5348

Closed
HARIKSREEE opened this issue Jan 14, 2020 · 2 comments

Comments

@HARIKSREEE
Copy link

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

Tue Jan 14 2020 20:37:32 GMT+0530 (India Standard Time)
1/14/2020, 8:37:53 PM
-330
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
@Alanscut
Copy link
Contributor

@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 ''
}

@marwahaha
Copy link
Member

Please re-open if you still have issues.

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

No branches or pull requests

3 participants