我在 TypeScript (Ionic2/Angular2) 项目中使用 moment.js。继从这个帖子 https://stackoverflow.com/questions/43042337/how-to-format-decimal-hours-greater-than-24-hours-into-hours-minutes-in-javascri,我现在想尝试一个插件时刻-持续时间-格式 https://github.com/jsmreese/moment-duration-format
我有 npm 包和类型定义,并且能够通过 import as..
import moment from 'moment';
...
let duration = moment.duration(decimalHours, 'hours');
我现在想用时刻-持续时间-格式 https://github.com/jsmreese/moment-duration-format
我已经通过安装npm install moment-duration-format --save
然后通过类型定义npm i @types/moment-duration-format --save
.
我可以看到两个 npm 模块。
与往常一样,如何使用此类类型定义总是存在一些谜团(包括 import 在内的用法似乎从未出现在任何 doco 中)。
我尝试过添加import 'moment-duration-format';
, import duration from 'moment-duration-format';
(moment-duration-format/index.d.ts' 不是一个模块。)
尝试使用时出现错误,如下所示。
let dd = moment.duration.format(400.99, 'hours').format('D:HH:mm');
// (TS error [ts] Property 'format' does not exist on type '(inp?: DurationInputArg1, unit?: DurationConstructor) => Duration'.
有谁知道如何使用它打字稿.
提前致谢