我目前正在将我的项目从ES5转换为ES6,但我遇到了MomentJS(version 2.18.1
)的问题.问题是我有几个变量是矩对象,但我不能对它们调用矩().
举个例子:
import * as moment from "moment";
export class DateThingy {
constructor(private moment) { //What type does this have??
}
public getDate(): moment.Moment {
return this.moment();
}
}
1) 如果我将类型设置为private moment
到private moment: moment
,WebStorm会抱怨:"cannot find name 'moment'."
2) 如果我将类型设置为private moment: moment.Moment
,那么对象已经更改,我无法再调用this.moment()
(它现在是一个对象,没有函数调用).cannot invoke an expression whose type lacks a call signiture. Type 'Moment' has no campatible call signatures.告诉我:"网络风暴"
3) 我不能再使用MomentStatic了,因为它没有导出.如果我输入private moment: moment.MomentStatic
,WebStorm会给我:"namespace 'moment' does not have an exported member 'MomentStatic'"
那么在这个例子中,我应该使用什么类型呢?