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

Typescript generics, TSX and trailing commas (prettier generates invalid syntax) #6114

Closed
jleclanche opened this issue May 12, 2019 · 0 comments · Fixed by #6115
Closed

Typescript generics, TSX and trailing commas (prettier generates invalid syntax) #6114

jleclanche opened this issue May 12, 2019 · 0 comments · Fixed by #6115
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!

Comments

@jleclanche
Copy link
Contributor

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:

type G<T> = any;
const myFunc = <T,>(arg1: G<T>) => false;

The generic's trailing comma gets removed, and it gets turned into the following invalid TSX (but valid TS):

type G<T> = any;
const myFunc = <T>(arg1: G<T>) => false;
@lydell lydell added the lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) label May 12, 2019
@duailibe duailibe added the status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! label May 13, 2019
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Aug 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants