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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47350589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:02:47  来源:igfitidea点击:

How to disable automatic import statements in VsCode October 2017

typescriptvisual-studio-code

提问by prmph

The latest version of VS Code installed a few days ago (the October 2017 update) keeps adding all kinds of strange import statements to the top of the .ts code file.

几天前安装的最新版 VS Code(2017 年 10 月更新)不断在 .ts 代码文件的顶部添加各种奇怪的导入语句。

For example, as I was editing a file, VsCode suddenly added a line like this to the top of the file:

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

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

How do I disable this behavior?

如何禁用此行为?

回答by Evgeniy Zaykov

"typescript.suggest.autoImports": false 
"javascript.suggest.autoImports": false

Fresh VS Code version. February 2019

全新的 VS Code 版本。2019 年 2 月

回答by Antoine Boisier-Michaud

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

您可以通过将此行添加到您的用户或工作区设置(File>Preferences>Settings、 或Code>Preferences>Settings)来禁用它。

"typescript.autoImportSuggestions.enabled": false

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

参考:https: //github.com/Microsoft/vscode/issues/38551

回答by nahoang

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

更新了新版本的VSCode 2019以使用 UI 修改设置。因此,选择文件 > 首选项 > 设置,然后auto在工作区部分中搜索。找到带有高亮字的 Javascrtip 或 Typescript,auto import然后选中或取消选中启用/禁用此功能。

Here is the picture for reference.

这是图片供参考。

enter image description here

在此处输入图片说明

回答by Kurt William

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

对于使用 React/JavaScript 的用户,您必须在 File > Preferences > Settings 中编辑此设置:

"javascript.updateImportsOnFileMove.enabled": "never",

回答by Quv

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

截至 2018 年 8 月 (1.25),已接受的答案并不总是有效。

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.

不知道这里发生了什么,但这些自动路径更改在我的环境中从未发生过。