【Angular】在vscode中,某些库接口,如SimpleChanges,没有导入,鼠标移上去,ts语言功能没有快速修复选项,如何能够恢复快速修复功能?

发布时间 2023-12-28 10:31:21作者: unuliha

It appears that until recently (before TypeScript 4 release) the only way to make auto-imports work was to import each library you need at least once in your project (does not matter where). After that VS Code supposed to start auto-import stuff from them.

Starting TS 4 the VS Code suppose to start doing it automatically (more concrete - auto-include from all the libraries specified in your package.json), though I've noticed that it uses the wrong paths to the code while importing - to the /dist/ folders as opposed to whatever a library exposes. As a result, Node.js might not be able to resolve and execute them. I've created an issue here

Note that in order this to work at all

  • Make sure your VS Code uses TS 4.0.2 or greater (as shown in the bottom right corner, click it to change)
  • You may need to set setting typescript.preferences.includePackageJsonAutoImports to on, because it your imports list exceeds 10 dependencies - it may/won't not scan them. See release notes for the details.

The bottom line - in order it to work correctly at the moment you still need to import (by hand) a new dependency in your code (anywhere) at least once and then VS Code auto-import will start working for that lib.

原文:https://stackoverflow.com/questions/63477929/visual-studio-code-auto-imports-quick-fix-does-not-work