Typescript generics, TSX and trailing commas (prettier generates invalid syntax) #6114
Labels
lang:typescript
Issues affecting TypeScript-specific constructs (not general JS issues)
locked-due-to-inactivity
Please open a new issue and fill out the template instead of commenting.
status:has pr
Issues with an accompanying pull request. These issues will probably be fixed soon!
Background
I was trying to have a generic function in a tsx file, but was using
const f = () ...
syntax. When a single-argument generic is added to that style of function, the parser switches to TSX mode.I came across this SO answer which explains that the parser will not switch to TSX mode if more than one generic argument is present.
So I discovered you can just add a trailing comma without having to have more than one argument. Problem is, prettier doesn't like that trailing comma and it gets cleaned up, which generates invalid tsx.
Reproduction
Run prettier over this:
The generic's trailing comma gets removed, and it gets turned into the following invalid TSX (but valid TS):
The text was updated successfully, but these errors were encountered: