10

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?

3 Answers 3

17

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)

0
3

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.

1

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
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.