如何在2017年10月的 VsCode 中禁用自动导入语句

几天前安装的最新版本的 VS Code (2017年10月的更新)一直在将各种奇怪的 import 语句添加到。代码文件。

例如,当我在编辑一个文件时,VsCode 突然在文件的顶部添加了这样一行:

import { Stack } from "../../../../../../../../../Repos/Web/node_modules/@types/d3";

我如何禁用这种行为?

47148 次浏览

You can disable it by adding this line to your user or workspace settings (File>Preferences>Settings, or Code>Preferences>Settings).

"typescript.autoImportSuggestions.enabled": false

Ref.: https://github.com/Microsoft/vscode/issues/38551

As of August 2018 (1.25), the accepted answer doesn't always work.

Instead, add this line to your folder-specific setting.

{  "typescript.preferences.importModuleSpecifier": "relative" }

Don't figure what's going on here, but those automatic path changes never happen in my environment.

For those using React/JavaScript you have to edit this setting in File > Preferences > Settings:

"javascript.updateImportsOnFileMove.enabled": "never",
"typescript.suggest.autoImports": false
"javascript.suggest.autoImports": false

Fresh VS Code version. February 2019

Updated for new version of VSCode 2019 for using the UI to modify the setting. So choose the File > Preference > Setting then search auto in the Workspace secton. Find the Javascrtip or Typescript with highlight word auto import then check or uncheck for enable / disalbe this function.

Here is the picture for reference.

enter image description here