Prettier removes Promise<void> type and other annotations in TypeScript arrow functions #3821
Replies: 28 comments
-
|
Same issue here. |
Beta Was this translation helpful? Give feedback.
-
|
I also have noticed this. I have a repo with a reproduction here: https://github.com/ianmitchell/tailwind-example If you open the repro and navigate to the page.tsx file and save, the extension will change the If I can do anything else to help debug this, happy to help! |
Beta Was this translation helpful? Give feedback.
-
|
+1 here |
Beta Was this translation helpful? Give feedback.
-
|
+1 here |
Beta Was this translation helpful? Give feedback.
-
|
I meet in the same issue after packages.json libraries update. Restarting Prettier VScode extension worked for me. |
Beta Was this translation helpful? Give feedback.
-
|
I had to remove this line of my vscode |
Beta Was this translation helpful? Give feedback.
-
|
+1 here Only way to fix was to remove this plugin: which we'd love to keep using... |
Beta Was this translation helpful? Give feedback.
-
Exact same situation here. Just added the plugin to a new repo and observed the behavior |
Beta Was this translation helpful? Give feedback.
-
Reinstalling the VSCode Prettier extentions appears to have solved this for me |
Beta Was this translation helpful? Give feedback.
-
|
For me Prettier 3.3.2 or lower does not exhibit this behavior. I narrowed it down to 3.3.3+ that does, which makes me wonder what changed in 3.3.3 that could have broken compatibility when using plugins and generics at the same time. Uninstalling and reinstalling the extension did not help, but disabling plugins also prevents the generics from being removed, so long as 0 plugins are configured. Related discussion on SO here |
Beta Was this translation helpful? Give feedback.
-
|
I don't have this issue in vscode, but only in the CLI. But same for me, removing the only plugin I had (prettier-plugin-tailwindcss) was solving the issue in the cli. For information though, weirdly I was used to use pnpm instead of npm and had no issue with pnpm. Not sure why it has to be different but maybe it helps. Update: I went back to prettier 3.4.2 and it solved the issue. Then I installed 3.5.0 again and it works. Looks like a npm install issue? |
Beta Was this translation helpful? Give feedback.
-
|
FWIW, I ran into this same issue after I updated my project typescript dependency from v4.9 to v5.7 and found my way here. The recommendation from @pawel-halat worked for me. I restarted my extensions and the problem went away. I was just about to give up and disable with a prettier-ignore comment. @cedeber , it might have worked for you because you effectively restarted the extension by switching versions. |
Beta Was this translation helpful? Give feedback.
-
|
FWIW, |
Beta Was this translation helpful? Give feedback.
-
|
I'm having the same problem with |
Beta Was this translation helpful? Give feedback.
-
|
There was no prettier in my package.json and I had the same problem. A simple |
Beta Was this translation helpful? Give feedback.
-
|
@nonpop 😄 Actually, for me, it was the exact opposite. I had the |
Beta Was this translation helpful? Give feedback.
-
|
I tried to fix it for 6 hours, edited the prettier.config.js, didn't sleep until 4am... |
Beta Was this translation helpful? Give feedback.
-
|
Upgrade prettier from 3.4.2 to 3.5.2 solved my problem. I use prettier-plugin-organize-imports as well. I use visual studio 2022 and typescript Analyzer(ESlint). Copy new installed prettier to C:\Users\xx\AppData\Local\Microsoft\VisualStudio\17.0_aa37ebb0\Extensions\nwyzzcs5.qrm\Node\node_modules. |
Beta Was this translation helpful? Give feedback.
-
|
I can also confirm that upgrading beyond 3.3.2 is now possible, I went straight to 3.5.3 without any issues. Curious which release fixed it, but not going to spend the time to find out. |
Beta Was this translation helpful? Give feedback.
-
it worked for me, i updated the prettier version in my global dependencies with |
Beta Was this translation helpful? Give feedback.
-
|
I must answer here, same problem. My solution is: Format Document With change Configure Default Formatter from Prettier-Code Format to Prettier Eslint, and the problem solved. I don't know why, but at least, the problem solved |
Beta Was this translation helpful? Give feedback.
-
|
for me, reinstall prettier solve the problem |
Beta Was this translation helpful? Give feedback.
-
It helped me. Thank you! |
Beta Was this translation helpful? Give feedback.
-
thanks! |
Beta Was this translation helpful? Give feedback.
-
|
This seems to be flaky. It happened to me today. Then I
The problem was gone after re-enabling plugins. It was randomly converting |
Beta Was this translation helpful? Give feedback.
-
|
adding |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Prettier removes Promise type annotations in TypeScript arrow functions, even with "arrowParens": "always" configured, making it impossible to satisfy TypeScript's requirement for generic type parameters on Promises.
Steps To Reproduce:
Expected result
Prettier should preserve the Promise type annotation when formatting TypeScript files, especially when "arrowParens": "always" is set.
Example:
Actual result
Prettier removes the type parameter, resulting in invalid TypeScript:
This causes TypeScript to error with "Generic type 'Promise' requires 1 type argument(s)".
Additional information
The only current workarounds are
// @ts-ignoreor// prettier-ignoreNeither solution is ideal for maintaining clean, type-safe code.
VS Code Version: 1.95.3
Prettier Extension Version: 11.0.0
OS and version: Ubuntu 24.04
Prettier Log Output
Beta Was this translation helpful? Give feedback.
All reactions