如何将 VSCode 中的默认导入提示从 ES6 更改为 commonjs? [英] How to change the default import hint in VSCode from ES6 to commonjs?

查看:106
本文介绍了如何将 VSCode 中的默认导入提示从 ES6 更改为 commonjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio Code 上打开了一小段 JavaScript,然后启用 @ts-check 以从 TypeScript 定义文件中获取类型提示.

I've a small piece of JavaScript that I open on Visual Studio Code, I then enable @ts-check to get type hinting from TypeScript definition files.

当我引用来自不同导入的类型时,VSCode 会给出提示并在文件开头添加以下代码:

When I refer to a type that comes from a different import VSCode will give the hint and add the following code to the beginning of the file:

import { SomeType } from 'some-module';

如果我正在使用 ES6,这是正确的,但目前我的目标是旧的运行时,并且更喜欢使用 commonjs 语法编写生成的代码:

This is correct if I'm working on ES6 but currently I'm targetting to older runtimes and would prefer to get the generated code be written using the commonjs syntax:

var SomeType = require('some-module').SomeType;

是否可以更改任何配置来实现此行为?

Is there any configuration I can change to achieve this behavior?

推荐答案

我也有类似的情况.我已经能够摆脱类型错误,但我似乎无法弄清楚如何让代码完成以在其选项中列出require"或module.exports".

I'm in a similar situation. I've been able to get rid of type errors but I can't seem to figure out how to get code completion to list 'require' or 'module.exports' in its options.

获取类型错误消息.

{编译器选项":{"module": "commonjs",目标":es2015"},排除":[node_modules"]}

{ "compilerOptions": { "module": "commonjs", "target": "es2015" }, "exclude": ["node_modules"] }

这篇关于如何将 VSCode 中的默认导入提示从 ES6 更改为 commonjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆