title: How do you format code on save in VS Code
body: <p>I would like to automatically format TypeScript code using the build-in formatter when I save a file in Visual Studio Code. </p>
  
  <p>I'm aware of the following options, but none of them is good enough: </p>
  
  <ul>
  <li>Format manually <code>Shift + Alt + F</code></li>
  <li>Format on type <code>"editor.formatOnType": true</code>
  
  <ul>
  <li>It formats the line when you press enter. Unfortunatelly, it leaves it unformatted when you mouse-click another line or press up/down arrow. </li>
  </ul></li>
  <li>Use existing extension
  
  <ul>
  <li>I tried this <a href="https://marketplace.visualstudio.com/items?itemName=gyuha.format-on-save" rel="noreferrer">one</a>, but it does not seem to work too well. </li>
  </ul></li>
  <li>Use beautify <code>"beautify.onSave": true</code>
  
  <ul>
  <li>It does not work with TypeScript</li>
  </ul></li>
  <li>Write custom extension
  
  <ul>
  <li>It's tricky if you want to handle autosaves and builds correctly. </li>
  </ul></li>
  </ul>