简体   繁体   English

如何在 Visual Studio Code 中使用 TypeScript 和 JavaScript 禁用自动导入的自动分号?

[英]How to disable automatic semicolon for auto imports with TypeScript and JavaScript in Visual Studio Code?

When working with VS Code and Typescript or JavaScript, VS Code suggests auto imports.使用 VS Code 和 Typescript 或 JavaScript 时,VS Code 建议自动导入。 But when inserting the import automatically, it will add a semicolon at the end of the line.但是当自动插入导入时,它会在行尾添加一个分号。 I do not want this semicolon.我不想要这个分号。 In addition, it is configured in my tslint as such.此外,它在我的 tslint 中也是如此配置的。

Is there anyway to tell VS Code to not to insert this semicolon?反正有没有告诉 VS Code 不要插入这个分号?

VS Code 1.38 tries to infer if semicolons should be used for auto imports and refactoring in JavaScript and TypeScript. VS Code 1.38 试图推断分号是否应该用于JavaScript 和 TypeScript 中的自动导入和重构。

With VS Code 1.39 and TypeScript 3.7+, you can also explicitly set if semicolons should be used or not:使用 VS Code 1.39 和 TypeScript 3.7+,您还可以明确设置是否应使用分号:

"javascript.format.semicolons": "remove",
"typescript.format.semicolons": "remove"

(Note that until VS Code 1.40 is released, you may need to install this extension in order to actually enable TypeScript 3.7 in VS Code) (请注意,在 VS Code 1.40 发布之前,您可能需要安装此扩展才能在 VS Code 中实际启用 TypeScript 3.7)

There is no way of doing that at the moment, for VSCode 1.30.2, TypeScript 3.3.对于 VSCode 1.30.2、TypeScript 3.3,目前没有办法做到这一点。

You can check out the feature request here: https://github.com/Microsoft/TypeScript/issues/19882您可以在此处查看功能请求: https : //github.com/Microsoft/TypeScript/issues/19882

But this feature may come in TypeScript 3.4, as @RyanCavanaugh updated the milestone to 3.4但是这个功能可能会在 TypeScript 3.4 中出现,因为@RyanCavanaugh 将里程碑更新为 3.4

In the meantime, I use semi-standard style.同时,我使用semi-standard样式。

Also, pure standard style does not work well in VSCode as the alignment is messed up:此外,纯standard样式在 VSCode 中效果不佳,因为对齐方式混乱:

function foo() {
  const x = {}

    ;['a'].map(x => console.log(x)) // <-- alignment is bad
}

In order to add to the responses:为了添加到响应:

The setting should be设置应该是

    "javascript.format.semicolons": "remove",
    "typescript.format.semicolons": "remove"

(Not "javascrriptscript.format.semicolons" ) (不是"javascrriptscript.format.semicolons"

The docs for settings say:设置文档说:

    "javascript.format.semicolons"

can have three different options:可以有三个不同的选项:

    "ignore" -> Dont insert or remove any semicolons.
    "insert" -> Insert semicolons at statement ends.
    "remove" -> Remove unnecessary semicolons.

As of now there still does not seem to be an option for the mentioned problem yet, as for me when using the autocomplete functionality for log aka console.log() it did add a semicolon to the end of the line.到目前为止,似乎仍然没有提到的问题的选项,至于我在使用log aka console.log()的自动完成功能时,它确实在行尾添加了一个分号。

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

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