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';
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);
Typescript error:
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?
Thanks for any help.
I just looked at the interfaces. You need to call
let range = moment.range(self.weekStart, self.weekEnd);
not moment().range
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
.