Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

Is there anyway to tell VS Code to not to insert this semicolon?

like image 283
Jose Avatar asked Feb 03 '19 04:02

Jose


3 Answers

VS Code 1.38 tries to infer if semicolons should be used for auto imports and refactoring in JavaScript and TypeScript.

With VS Code 1.39 and TypeScript 3.7+, you can also explicitly set if semicolons should be used or not:

"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)

like image 123
Matt Bierner Avatar answered Nov 01 '22 08:11

Matt Bierner


There is no way of doing that at the moment, for VSCode 1.30.2, TypeScript 3.3.

You can check out the feature request here: https://github.com/Microsoft/TypeScript/issues/19882

But this feature may come in TypeScript 3.4, as @RyanCavanaugh updated the milestone to 3.4

In the meantime, I use semi-standard style.

Also, pure standard style does not work well in VSCode as the alignment is messed up:

function foo() {
  const x = {}

    ;['a'].map(x => console.log(x)) // <-- alignment is bad
}
like image 36
unional Avatar answered Nov 01 '22 10:11

unional


In order to add to the responses:

The setting should be

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

(Not "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.

like image 21
Mr_Robot Avatar answered Nov 01 '22 10:11

Mr_Robot