简体   繁体   English

在 VSCode 中使用 Prettier 格式化打字稿?

[英]Formatting typescript with Prettier in VSCode?

Right now when I press ctrl+shift+p and select format document, code gets formatted like this:现在,当我按 ctrl+shift+p 并选择格式化文档时,代码的格式如下:

   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.我正在使用Prettier格式扩展。

printWidth is what you search for. printWidth是您要搜索的内容。 -> https://prettier.io/docs/en/options.html -> https://prettier.io/docs/en/options.html

But you will have other problems with tslint and prettier.但是你会遇到 tslint 和 prettier 的其他问题。 Try a plugin like this.试试这样的插件。 -> https://alexjoverm.github.io/2017/06/12/Use-Prettier-with-TSLint-and-be-happy/ -> https://alexjoverm.github.io/2017/06/12/Use-Prettier-with-TSLint-and-be-happy/

将以下代码添加到您的 setting.json 文件中:

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

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

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