简体   繁体   English

当我使用 typescript 时导入丑陋

[英]ugly import when I use typescript

I have a problem about ugly imports when i use typescript and when i import a third-party library that made with Javascript and after install its declaration type file with @types/[library-name] in vscode.当我使用 typescript 以及导入使用 Javascript 制作的第三方库并在 vscode 中使用 @types/[library-name] 安装其声明类型文件后,我遇到了关于丑陋导入的问题。

actually i was importing the library to my app when i noticed something wrong.实际上,当我发现有问题时,我正在将库导入我的应用程序。

the import is done from "node_modules/@types/[library-name]".导入是从“node_modules/@types/[library-name]”完成的。

for example i installed inquirer library with @types/inquirer(package.json)例如,我使用 @types/inquirer(package.json) 安装了查询器库

{
  "name": "ch01",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/inquirer": "^9.0.1",
    "inquirer": "^9.1.1"
  }
}

then i imported it in my app:然后我将它导入我的应用程序: 在此处输入图像描述

if you note to path of the import you note that problem.如果您注意导入路径,您会注意到该问题。

how do i resolve this problem???我该如何解决这个问题???

make sure you installed right version.确保您安装了正确的版本。 Inquirer 9 and higher works with that syntax. Inquirer 9 及更高版本使用该语法。 const inquirer = require('inquirer'); work for older versions perfectly.完美适用于旧版本。 If older versions are okay for your code.如果旧版本适用于您的代码。 You must try the older one with that syntax.您必须尝试使用该语法的旧版本。

If you still want to use 9 and higher.如果您仍想使用 9 及更高版本。 You can use a constructor.您可以使用构造函数。 It may help.它可能会有所帮助。

暂无
暂无

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

相关问题 我们什么时候使用 typescript import * as? - When do we use typescript import * as? 使用打字稿2.0时使用量角器4.0.9时无法在Jasmine2规范中使用import - I cannot use import in Jasmine2 spec when using protractor 4.0.9 when using typescript 2.0 如何仅导入我将在 Typescript 上动态使用的类 - How to import only the class that I'll use dynamically on Typescript 如何在打字稿中导入/使用 Reflect - How to import/use Reflect in typescript 导入模块时不能在模块外使用 import 语句 - Cannot use import statement outside a module when I import a module 运行编译的 Javascript 代码时,TypeScript 文件中出现“语法错误:无法在模块外使用导入语句”错误 - "SyntaxError: Cannot use import statement outside of a module" error in a TypeScript file when running compiled Javascript code 将已编译的 Typescript 文件相互导入时出现“未捕获的语法错误:无法在模块外使用 import 语句” - “Uncaught SyntaxError: Cannot use import statement outside a module” when importing compiled Typescript files to each other 有没有一种方法可以强制TypeScript编译器在转换'import'和'export'关键字时使用RequireJs而不是Browserify? - Is there a way to force TypeScript compiler to use RequireJs rather than Browserify when converting 'import' and 'export' keywords? 在TypeScript中使用import / require来获取接口声明 - Use import/require in TypeScript to get interface declarations 导入打字稿时如何在路径中使用变量 - How use variable in the path while import typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM