时刻范围插件的打字稿错误

问题描述:

我在Ionic 2应用程序中包含时刻js 时刻范围插件,如下所示:

I have included moment js and the moment-range plugin in my Ionic 2 app like so:

import * as moment from 'moment';
import 'moment-range';

这个工作正常,我可以同时使用它们,但Typescript给了我以下错误:

This works fine and I can use them both, but Typescript gives me the following error:

Javascript:

let range = moment().range(self.weekStart, self.weekEnd);

打字稿错误:

Error TS2339: Property 'range' does not exist on type 'Moment'.

我已经运行以下命令尝试通过安装打字文件来阻止此错误:

I have ran the following command to try and stop this error by installing a typings file:

typings install moment-range --ambient --save

但它似乎没有任何影响。还有其他我需要做的事情或有没有办法来消除错误?

but it doesn't seem to have had any effect. Is there something else I need to do or is there a way of silencing the error?

感谢您的帮助。

我只看了接口。你需要打电话

I just looked at the interfaces. You need to call

let range = moment.range(self.weekStart, self.weekEnd);

不是时刻()。范围

如果你看 moment-range.d.ts 你会看到range方法是在静态接口 MomentStatic 上定义的,而不是实例接口时刻

If you look at moment-range.d.ts you'll see that the range method is defined on the static interface MomentStatic, not the instance interface Moment.