简体   繁体   English

Visual Studio Code智能感知可导入整个模块

[英]Visual Studio Code intellisense for import entire module

Visual Studio Code's intellisense works great out of the box for importing a single or multiple exports. Visual Studio Code的智能感知功能非常适合直接导入单个或多个导出。

However, I want intellisense for importing entire module like so: 但是,我想要像这样导入整个模块的intellisense:

import * as MyModule from 'path/to/MyModule';

So when I start typing MyM... , I want intellisense to kick in, and suggest to import the entire module. 因此,当我开始输入MyM... ,我希望intellisense可以加入,并建议导入整个模块。 Is there a setting or plugin for this? 是否有为此设置或插件?

Most of the time the named exports are member of the default export so import MyModule from 'path/to/MyModule' may be an import suggestion already. 大多数情况下,命名导出是默认导出的成员,因此import MyModule from 'path/to/MyModule'导入import MyModule from 'path/to/MyModule'可能已经是导入建议。

If you are the author of the module, just add a default export along with the named exports of your module: 如果您是模块的作者,只需添加默认导出以及模块的命名导出即可:

export A;
export B;
export C;

export default { A, B, C };

If you are not the author and the module does not provide a default export, you can still wrap your module into a new module doing that for you: 如果您不是作者,并且该模块未提供默认导出,则仍可以将您的模块包装到一个新模块中,为您完成此操作:

import * as MyModule from 'path/to/MyModule';

export default MyModule;

One way or another, MyModule has to be defined for the intellisense to kick in... 一种或另一种方式,必须定义MyModule才能使智能感知发挥作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM