fix(formatter): preserve trailing comma in TSX arrow functions with default type params#21151
Merged
leaysgur merged 1 commit intooxc-project:mainfrom Apr 8, 2026
Conversation
…efault type params Trailing commas are required in single-param generic arrow functions in .tsx files to disambiguate from JSX. A default type alone does not disambiguate, so the comma must still be forced — only a constraint (extends clause) provides sufficient disambiguation. Closes oxc-project#21150 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5208845 to
ea5bfe1
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #21150
When a single-parameter generic arrow function in a
.tsxfile has a default type (e.g.<Options = any>), the formatter was incorrectly removing the trailing comma. Prettier preserves it as<Options = any,>.The existing
should_force_trailing_comma_for_arrow_functionlogic handles the simple case (<T,>) correctly, but it also skipped forcing the comma when the parameter had a default type. Prettier's equivalent only skips the forced comma when a constraint (extendsclause) is present — not for default types. This PR aligns with that behavior.Input
Before (incorrect)
After (matches Prettier)
Root cause
In
should_force_trailing_comma_for_arrow_function(type_parameters.rs), the early-return condition checked for both a constraint and a default type:Prettier's equivalent only skips forcing the comma when a constraint is present. See Prettier source.
Fix
Removed
|| t.default().is_some()from the condition:Prettier conformance: no regressions (746/753 JS, 591/601 TS — unchanged).
AI Disclosure
This PR was co-authored with Claude Code (AI assistant), as noted in the commit. The fix was reviewed, tested against the full Prettier conformance suite, and verified to produce no regressions.