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

Missing trailing comma in TSX arrow single type param #12076

Closed
nicolo-ribaudo opened this issue Jan 11, 2022 · 4 comments
Closed

Missing trailing comma in TSX arrow single type param #12076

nicolo-ribaudo opened this issue Jan 11, 2022 · 4 comments

Comments

@nicolo-ribaudo
Copy link
Contributor

Prettier 2.5.1
Playground link

--parser babel-ts

Input:

let arr = <T,>() => <div></div>;

Output:

let arr = <T>() => <div></div>;

Expected behavior:

It should print the trailing comma.

let arr = <T,>() => <div></div>;

When using TSX, arrow functions with a single type argument must have a trailing comma to disambiguate it from JSX. Babel currently has a bug and parses <T>() => <div></div>, but TS doesn't. We are fixing the Babel bug at babel/babel#14135.

@kachkaev
Copy link
Member

kachkaev commented Jan 11, 2022

Looks like a duplicate of #6114 and #6302. You can try writing let arr = <T,>() => <div></div>; in Example.tsx and the comma will preserve.

@nicolo-ribaudo
Copy link
Contributor Author

In the playground link it's not preserved 🤔

@nicolo-ribaudo
Copy link
Contributor Author

Oh I see, even if the playground parses TSX it doesn't not print as if the output file was .tsx.

@tianyingchun
Copy link

tianyingchun commented Mar 17, 2022

it seems that this issue also can be reproduce. #12479 (comment)

writing let arr = <T,>(s:T) =>

{s}
; in Example.tsx and the comma will preserve. works fine.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants