Ole
Ole

Reputation: 47212

Formatting typescript with Prettier in VSCode?

Right now when I press ctrl+shift+p and select format document, code gets formatted like this:

   const validators: Array<
     ValidationContext
   > = ValidationContainer.getValidationContexts(key);

I would like it to look like this:

   const validators: Array<ValidationContext> =
         ValidationContainer.getValidationContexts(key);

Any ideas on what switches I can flip? I'm using the Prettier formatting extension.

Upvotes: 6

Views: 8024

Answers (2)

Add codes below to your setting.json file:

"[typescript]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }

Upvotes: 4

atilkan
atilkan

Reputation: 5056

printWidth is what you search for. -> https://prettier.io/docs/en/options.html

But you will have other problems with tslint and prettier. Try a plugin like this. -> https://alexjoverm.github.io/2017/06/12/Use-Prettier-with-TSLint-and-be-happy/

Upvotes: 5

Related Questions