How to use moment-duration-format in TypeScript?

前端 未结 4 1231
忘掉有多难
忘掉有多难 2021-02-19 06:00

I am using moment.js in my TypeScript (Ionic2/Angular2) project. Following on from this post, I now want to try out a plugin moment-duration-format

I have the npm packag

4条回答
  •  醉酒成梦
    2021-02-19 06:16

    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).

提交回复
热议问题