ugly import when I use typescript

Viewed 50

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.

actually i was importing the library to my app when i noticed something wrong.

the import is done from "node_modules/@types/[library-name]".

for example i installed inquirer library with @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: enter image description here

if you note to path of the import you note that problem.

how do i resolve this problem???

1 Answers

make sure you installed right version. Inquirer 9 and higher works with that syntax.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. You can use a constructor. It may help.

Related