gpt4 book ai didi

angular - 属性 'format' 在类型 'Duration' 上不存在

转载 作者:行者123 更新时间:2023-12-03 21:27:46 28 4
gpt4 key购买 nike

我正在尝试在 TypeScript 中使用“moment-duration-formation”,但是,即使它有效,webpack 仍然提示它无法在线上找到“format”方法:

return moment.duration(value, "minutes").format("...");

这是 package.json
{
"devDependencies": {
"@types/moment-duration-format": "^1.3.7"
},
"dependencies": {
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0"
}
}

和 tsconfig.json:
{
"compilerOptions": {
"typeRoots": [ "./node_modules/@types" ]
}
}

在 (angular2) 组件中:
import * as moment from "moment";
import * as momentDurationFormat from "moment-duration-format";

...

let result: string = moment.duration(this.selectedHangarDistance * 10, "minutes").format("...")

我也试过
import "moment-duration-format";

但它不会改变任何东西:

ERROR in [at-loader] ./src/app/components/building/shop/shop.component.ts:190:81 TS2339: Property 'format' does not exist on type 'Duration'.

最佳答案

一个对我有用的解决方案:

import * as moment from "moment";
import momentDurationFormatSetup from "moment-duration-format";
momentDurationFormatSetup(moment);
* as moment显着为 import moment from "moment"通过时导致类型问题 momentDurationFormatSetup .

关于angular - 属性 'format' 在类型 'Duration' 上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837989/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com