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] Add trailing comma for only arrow functions in tsx. #6190
Conversation
Sorry, this bug is cause by my mistake. Also, this feature does not happen on playground. I want somebody to check this on local environment. |
src/language-js/printer-estree.js
Outdated
@@ -3003,12 +3003,14 @@ function printPathNoParens(path, options, print, args) { | |||
// Keep comma if the file extension is .tsx and | |||
// has one type parameter that isn't extend with any types. | |||
// Because, otherwise formatted result will be invalid as tsx. | |||
const grandParent = path.getNode(2); | |||
if ( | |||
parent.params && | |||
parent.params.length === 1 && | |||
options.filepath && | |||
options.filepath.match(/\.tsx/) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, please improve this regexp a bit: /\.tsx$/i
Also it's better to rewrite the last two lines using test
: /\.tsx$/i.test(options.filepath)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix from b961cdc .
@sosukesuzuki Don't worry about that! It's my fault that I didn't see that could happen |
Fix #6189 .
Prettier inserts a trailing comma to single type parameter for arrow functions in tsx, since v 1.18 (#6115 ). But, this feature inserts a trailing comma to type parameter for besides arrow functions too (e.g, function , interface ).
docs/
directory)CHANGELOG.unreleased.md
file following the template.✨Try the playground for this PR✨