I am trying to import the moment-range package into my Angular 4.x application the official documentation shows this :-
import Moment from 'moment';
import { extendMoment } from 'moment-range';
const moment = extendMoment(Moment);
However in my application moment has been added by the following method :
import * as Moment from 'moment';
So I decided to use the same method to try and get moment-range to work
import * as Moment from 'moment';
import * as MomentRange from 'moment-range';
const moment = MomentRange(Moment);
However I am getting the following typescript error - can anyone suggest how I fix this?
Cannot invoke an expression whose type lacks a call signature.
Type 'typeof "/node_modules/moment-range/dist/moment-range"'
has no compatible call signatures.
Found this on github and it worked for me - hope it helps others
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]));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.