[英]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.