Currently in the process of upgrading my project from ES5 to ES6, I've encountered a problem with MomentJS (version 2.18.1). The issue arises when dealing with variables that are Moment objects and the inability to call moment() on them.
For instance:
import * as moment from "moment";
export class DateThingy {
constructor(private moment) { //What type does this have??
}
public getDate(): moment.Moment {
return this.moment();
}
}
1) Setting the type of private moment
to private moment: moment
causes WebStorm to display an error: "cannot find name 'moment'."
2) Assigning the type as private moment: moment.Moment
results in an object change where calling this.moment()
is no longer possible. Webstorm indicates: "cannot invoke an expression whose type lacks a call signature. Type 'Moment' has no compatible call signatures."
3) Due to MomentStatic not being exported, using
private moment: moment.MomentStatic
prompts WebStorm to show: "namespace 'moment' does not have an exported member 'MomentStatic'"
Therefore, what kind of typing should be used in this scenario?