vscode auto import with already exists code

806 Views Asked by At

Sometimes i have already predefined code and i want functions to autoimport with Quick Fix action is it possible ? enter image description here

1

There are 1 best solutions below

0
On

VS Code is conservative when checking JavaScript code. Variables such as beforeSaveWarrior may be a global defined somewhere else (this is a surprisingly common pattern in JavaScript land). This means that using an undefined variable such as beforeSaveWarrior is not considered an error by default.

To show undefined variables as errors and get quick fixes that import them, you need to enable semantic checking in your Js file. The easiest way to to do this is to add // @ts-check at the top of your JavaScript file. Now undefined variables such as beforeSaveWarrior will be marked as errors. The lightbulb for the error should include a fix that adds the import