简体   繁体   English

如何导入TypeScript定义文件的文件

[英]How to import file for TypeScript definition file

I am trying to update the TypeScript definition file for react-toolbox found here 我正在尝试更新此处找到的react-toolbox的TypeScript定义文件

I have fixed a number of compile errors and now I have: 我修复了一些编译错误,现在我已经:

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

relating to the following code in the definition file : definition file的以下代码有关:

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

I have installed the definition file using typings and my typings.json file includes: 我使用typings.json安装了定义文件,我的typings.json文件包括:

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

I am using the npm install method because in my tsconfig.json I use exclude and it is not found automatically: 我使用的是npm install方法,因为在我的tsconfig.json中我使用了排除,但是没有自动找到它:

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

tsconfig.json uses "node" module resolution tsconfig.json使用“node”模块解析

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

I'm not sure if I've incorrectly configured the consuming project to be able to find the files in node_modules, or the TypeScript definition file needs to be modified to conform to a standard way of achieving this. 我不确定我是否错误地配置了消费项目以便能够在node_modules中找到文件,或者需要修改TypeScript定义文件以符合实现此目标的标准方法。 I would like to achieve this in the standard way so I can make a pull request and have it updated. 我想以标准方式实现这一点,以便我可以提出拉取请求并让它更新。

Are all these module declarations even needed, or could it be simplified? 是否所有这些模块声明都需要,还是可以简化?

Looks like this was related to using npm link and webpack. 看起来这与使用npm link和webpack有关。 I have unlinked react-toolbox and overwrote the version in the Typings directory with my own and it seems to work. 我有unlinked react-toolbox并用我自己的版本覆盖了Typings目录中的版本,它似乎工作。

I have also found this link , which I will try later to see if I can get npm link working again. 我也找到了这个链接 ,我稍后会尝试看看我是否可以再次使用npm链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM