【发布时间】:2020-10-03 15:29:49
【问题描述】:
我正在尝试创建一个适用于金额的 Angular2 应用程序。我正在尝试使用 dinero.js 来表示货币价值,但我很难使用 Typescript 中的某些功能。
按照说明,我使用此命令为dinero.js 安装了DefiniteTyped 映射
npm install @types/dinero.js --save
此库的类型映射声明为here。
我像这样将库导入到我的代码中:
import * as Dinero from 'dinero.js';
这允许我使用工厂函数Dinero。问题是,该声明列出了一些我想使用但似乎无法使用的函数(即maximum 和minimum)。
如果我尝试Dinero.maximum(...),我会得到:
"export 'maximum' (imported as 'Dinero') was not found in 'dinero.js'
如果我尝试直接导入这些函数:
import {maximum, minimum} from 'dinero.js';
拨打maximum(...),我得到:
"export 'minimum' was not found in 'dinero.js'
我如何真正使用这些功能?
【问题讨论】:
-
你必须像这样导入
Dineroimport Dinero from 'dinero.js' -
当我这样做时,我的 IDE 对我大喊
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.是启用这种不好的做法还是没问题?如果没问题,为什么默认禁用? -
不管怎样,我尝试启用该标志,现在我收到此错误:
core.js:6260 ERROR Error: Uncaught (in promise): TypeError: dinero_js__WEBPACK_IMPORTED_MODULE_2__ is not a function
标签: angular typescript definitelytyped