时刻范围插件的打字稿错误 [英] Typescript error with moment range plugin

查看:128
本文介绍了时刻范围插件的打字稿错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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.

这篇关于时刻范围插件的打字稿错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆