如何将 VSCode 中的默认导入提示从 ES6 更改为 commonjs?

编程入门 行业动态 更新时间:2024-10-26 14:38:09
本文介绍了如何将 VSCode 中的默认导入提示从 ES6 更改为 commonjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 09:18:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   提示   commonjs   VSCode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!