gpt4 book ai didi

typescript - 如何为 TypeScript 定义文件导入文件

转载 作者:搜寻专家 更新时间:2023-10-30 21:14:17 26 4
gpt4 key购买 nike

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

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

ERROR in /myproject/typings/main/definitions/react-toolbox/index.d.ts (1047,8): error TS2664: Invalid module name in augmentation, module 'react-toolbox/lib/app_bar' cannot be found.

关于定义文件中的如下代码:

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 定义文件以符合实现此目的的标准方法。我想以标准方式实现这一点,这样我就可以提出拉取请求并对其进行更新。

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

最佳答案

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

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

关于typescript - 如何为 TypeScript 定义文件导入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36820409/

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