I am currently converting my project from ES5 to ES6, but I am running into an issue with MomentJS (version 2.18.1
). The problem is that I have a few variables that
As Mike McCaughan said, the moment object cannot be injected in the constructor. Somehow this was possible with an old version of MomentJS. this could be resolved by removing the constructor property and accessing the global moment object that is included via import * as moment from "moment"
.
The function moment()
returns a Moment
object. This can be typed via moment.Moment
.
So the code can be rewritten as follows:
import * as moment from "moment";
export class DateThingy{
constructor() {
}
public getDate(): moment.Moment {
return moment();
}
}