For me Prettier has been doing an awesome job when auto-formatting JavaScript code on save. However, when using TypeScript files with React/JSX (.tsx) it didn’t work. Here is how to fix it:
First, press shift + cmd + p (Mac), enter “settings” and choose “Preferences: Open Settings (JSON)”. Then add the following:
"[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
Make sure you have set "editor.formatOnSave": true
That’s it! Happy coding! :-)
Oldest comments (19)
Are you sure .tx is Typescript and not .ts ?
Actually it's supposed to be .tsx :-) (fixed in post)
Good catch tho! Thanks for pointing out.
how to do on the windows10?
Ctrl + Shift + P
OPen the vscode and press Ctrl + P
Thank you.
Thank you .. 😊 .
Wow, this was exactly what I was looking for!
It worked! thank you
Thank you so much!
Thank you so much!
Thanks for this.
it works...
thanks