javascript - 如何在 Typescript 中正确导入 MomentJS 解决以下错误 : "Type ' typeof moment' has no compatible call signatures.》

标签 javascript angular typescript momentjs

导入 MomentJS 导致以下错误:

ERROR in [...] Cannot invoke an expression whose type lacks a call signature. Type 'typeof moment' has no compatible call signatures.

如何解决此错误?

最佳答案

最新版本的 MomentJS 现在已经定义了类型。重新安装 MomentJS,无需外部类型。您还应该避免命名空间样式导入,因为无法调用或构造此类导入,并且会导致运行时失败。

要走的路是传统导入:

从“时刻”导入时刻;

关于javascript - 如何在 Typescript 中正确导入 MomentJS 解决以下错误 : "Type ' typeof moment' has no compatible call signatures.》,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55131138/

相关文章:

javascript - 使用 Javascript 将文件读入数组 - 似乎无法使其工作

angular - 从Mat-Stepper Angular Material 覆盖默认图标

node.js - npm install 在 @angular/cli@9.1.3 安装后脚本失败

typescript - Firebase - 使用 Firestore 的 FieldValue

angular - Ionic 2 - 同时有多个菜单(右 - 左)

javascript - 基于 JavaScript 中的字符串创建自定义配色方案

javascript - 打印前 2 个不重复的数字 javascript

javascript - 根据高度 overflow hidden 元素

javascript - 我可以使用 JavaScript 开发 Angular 5 应用程序吗?

angularjs - 如何在具有 Angular 注入(inject)参数的 typescript 中创建新对象