Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier removes Promise<void> type and other annotations in TypeScript arrow functions #3578

Open
danielbjornadal opened this issue Nov 22, 2024 · 4 comments

Comments

@danielbjornadal
Copy link

danielbjornadal commented Nov 22, 2024

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:

  1. Create a new TypeScript file with an interface containing Promise return types
  2. Configure Prettier with "arrowParens": "always"
  3. Save the file and observe Prettier's formatting
  4. Note that TypeScript shows an error: "Generic type 'Promise' requires 1 type argument(s)"

Expected result

Prettier should preserve the Promise type annotation when formatting TypeScript files, especially when "arrowParens": "always" is set.

Example:

interface Example {
  myFunction: (param: string) => Promise<void>;
}

Actual result

Prettier removes the type parameter, resulting in invalid TypeScript:

interface Example {
  myFunction: (param: string) => Promise;
}

This causes TypeScript to error with "Generic type 'Promise' requires 1 type argument(s)".

Additional information

The only current workarounds are // @ts-ignore or // prettier-ignore

Neither 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

[INFO] Prettier Options:
{
  "plugins": ["@trivago/prettier-plugin-sort-imports"],
  "importOrder": [...],
  "importOrderSeparation": true,
  "importOrderSortSpecifiers": true,
  "printWidth": 120,
  "arrowParens": "always"
}
[INFO] Prettier Resolution: Prettier Path: /Users/[username]/project/node_modules/prettier
[INFO] Formatting file:///Users/[username]/project/src/types.ts
[INFO] Formatting completed in 0.1s
@danielbjornadal danielbjornadal changed the title Prettier removes Promise<void> type annotations in TypeScript arrow functions Prettier removes Promise<void> type and other annotations in TypeScript arrow functions Nov 22, 2024
@madaxen86
Copy link

Same issue here.
Temporary workaround is to remove the plugins. No matter what plugins I think, cause I had
"@trivago/prettier-plugin-sort-imports",
"prettier-plugin-tailwindcss",
The error occurred no matter which I disabled, as long as one is active.

@IanMitchell
Copy link

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 Promise<number> function return signature to Promise. This doesn't happen when prettier is invoked via the CLI.

If I can do anything else to help debug this, happy to help!

@jjram19
Copy link

jjram19 commented Dec 19, 2024

+1 here

1 similar comment
@davidy3k
Copy link

+1 here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants