【问题标题】:How to import file for TypeScript definition file如何为 TypeScript 定义文件导入文件
【发布时间】:2016-08-17 15:41:34
【问题描述】:

我正在尝试更新发现 here 的 react-toolbox 的 TypeScript 定义文件

我已经修复了一些编译错误,现在我有:

/myproject/typings/main/definitions/react-toolbox/index.d.ts 中的错误 (1047,8):错误 TS2664:扩充模块中的模块名称无效 'react-toolbox/lib/app_bar' 找不到。

definition file中的以下代码有关:

declare module 'react-toolbox' {
    import AppBar from 'react-toolbox/lib/app_bar';

我已经使用typings安装了定义文件,我的typings.json文件包括:

"dependencies": {
  "react-toolbox": "npm:react-toolbox",

我正在使用 npm install 方法,因为在我的 tsconfig.json 中我使用了 exclude 并且没有自动找到它:

"exclude": [
    "node_modules",
    "typings/browser",
    "typings/browser.d.ts"
],

tsconfig.json 使用“节点”模块解析

"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",

我不确定我是否错误地将使用项目配置为能够在 node_modules 中找到文件,或者需要修改 TypeScript 定义文件以符合实现此目的的标准方式。我想以标准方式实现这一点,以便我可以提出拉取请求并进行更新。

是否需要所有这些模块声明,或者是否可以简化?

【问题讨论】:

    标签: typescript react-toolbox


    【解决方案1】:

    看起来这与使用 npm 链接和 webpack 有关。我已经取消链接 react-toolbox 并用我自己的版本覆盖了 Typings 目录中的版本,它似乎可以工作。

    我还找到了this link,我稍后会尝试看看是否可以让 npm 链接再次工作。

    【讨论】:

    • 您能否详细说明您为解决此问题所做的工作?
    • @VladyslavZavalykhatko 这是不久前的事,所以我不记得具体了。我可能使用了npm unlink 或删除了节点模块并重新安装。
    猜你喜欢
    • 2017-02-02
    • 2020-01-28
    • 2018-04-10
    • 1970-01-01
    • 2017-07-21
    • 2020-07-25
    • 2020-03-22
    • 2012-10-07
    • 2019-08-01
    相关资源
    最近更新 更多