【问题标题】:Importing moment-range into Angular 4.x application (ES6) - no compatible call signatures error?将矩范围导入 Angular 4.x 应用程序(ES6) - 没有兼容的调用签名错误?
【发布时间】:2018-06-21 11:13:28
【问题描述】:

我正在尝试将 moment-range 包导入到我的 Angular 4.x 应用程序中,官方文档显示了这一点:-

import Moment from 'moment';
import { extendMoment } from 'moment-range';
const moment = extendMoment(Moment);

但是在我的应用程序中,已经通过以下方法添加了时刻:

import * as Moment from 'moment';

所以我决定使用相同的方法来尝试让矩范围工作

import * as Moment from 'moment';
import * as MomentRange from 'moment-range';
const moment = MomentRange(Moment);

但是我收到以下打字稿错误 - 谁能建议我如何解决这个问题?

Cannot invoke an expression whose type lacks a call signature. 
Type 'typeof "/node_modules/moment-range/dist/moment-range"' 
has no compatible call signatures.

【问题讨论】:

    标签: javascript angular typescript momentjs


    【解决方案1】:

    在 github 上找到了这个,它对我有用 - 希望它可以帮助其他人

    import * as moment from 'moment';
    import { extendMoment } from 'moment-range';
    
    const { range } = extendMoment(moment);
    
    const timeRange = range(moment.utc([2015, 0, 1]), moment.utc([2015, 5, 1]));
    

    【讨论】:

      猜你喜欢
      • 2019-09-23
      • 1970-01-01
      • 2018-11-14
      • 2018-11-28
      • 2017-12-28
      • 2017-12-29
      • 1970-01-01
      • 2020-05-17
      • 2016-12-18
      相关资源
      最近更新 更多