-
Notifications
You must be signed in to change notification settings - Fork 202
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
TypeScript error with extendMoment() #263
Comments
They only way I got this to work in "typescript": "3.4.5"
|
Thanks @nareshbhatia! I've updated the docs to reflect that fix :) |
@TristanJM, it's a workaround at best :-). TypeScript is getting very popular in the React circles now, so finding a natural solution would be good. |
Sadly above also failed and gave me lint errors. I fixed it like this.
but even this latest iteration has a problem where calling moment default functions causes this error.
|
This workaround works for me: // This line has changed. I think "* as Moment" is wrong.
import Moment from "moment";
import { extendMoment } from "moment-range";
// Current latest release has wrong type definition,
// so I put any casting to avoid errors.
const moment = extendMoment(Moment as any); |
I've come across this problem and came up with the following: import * as Moment from 'moment'
import { extendMoment } from 'moment-range'
const { default: moment, range: momentRange } = extendMoment(Moment) I couldn't find an approach that allows to write |
Just spent a day trying to figure out why |
Following the ES6 installation instructions to use moment-range with TypeScript 3.4.5 I was getting the following error on
extendMoment()
:I had to change the moment import statement as follows to get rid of this error:
Surprisingly, the original import statement works perfectly fine in other files that do not use
moment-range
(I useesModuleInterop: true
in tsconfig).For example, this works fine:
Would be good to document the correct way to use moment-range with TypeScript.
The text was updated successfully, but these errors were encountered: