How to use moment-duration-format in TypeScript?
You are using duration
as a property instead of invoking it. Try:
let dd = moment.duration(400.99, 'hours').format('D:HH:mm');
This is actually not a TypeScript problem. It wouldn't work with JavaScript either. In JavaSctript you would get a runtime error while TypeScript doesn't let you do it at compile time (proving its worth).
I was using the workaround here, but it now looks like the ype def has been fixed. Getting an update of the type def So I can do the following...
import * as moment from 'moment';
import 'moment-duration-format';
let duration = moment.duration(decimalHours, 'hours') ;
let options : moment.DurationFormatSettings = {
forceLength : false,
precision : 0,
template : formatString,
trim : false
};
let result = duration.format(formatString, 0, options);