fix(fmt): surround template literal type unions with newlines when too long#34462
Open
divybot wants to merge 1 commit into
Open
fix(fmt): surround template literal type unions with newlines when too long#34462divybot wants to merge 1 commit into
divybot wants to merge 1 commit into
Conversation
…o long
A `TsUnionType` (or `TsIntersectionType`) inside a `${...}` placeholder
of a `TsTplLitType` would break only on the union separator (`|` / `&`)
when the line exceeded the configured width, leaving the closing `}`
glued onto the last union element's line. The minimal repro from #29868
is
```ts
export type SortSelector = `${typeof Descending | typeof Ascending}${SortItems}`;
```
which formatted to
```ts
export type SortSelector = `${
| typeof Descending
| typeof Ascending}${SortItems}`;
```
instead of the expected
```ts
export type SortSelector = `${
typeof Descending | typeof Ascending
}${SortItems}`;
```
The fix is in `dprint-plugin-typescript`
(dprint/dprint-plugin-typescript#794), which adds `TsUnionType` and
`TsIntersectionType` to the `get_possible_surround_newlines` match
inside `gen_template_literal` so the existing
`surround_with_newlines_indented_if_multi_line` codepath handles them
the same way it already handles `BinExpr` / `CondExpr` placeholders.
Until the next dprint-plugin-typescript release ships that fix, this
PR consumes it via a `[patch.crates-io]` against a fork branch; the
patch should be removed and the version pin bumped once the upstream
release is available.
Adds a spec regression test in
`tests/specs/fmt/template_literal_type_union` covering the issue's
exact input and the expected formatted output.
Closes denoland/orchid#258
Co-Authored-By: Divy Srivastava <me@littledivy.com>
Member
|
@divybot Add an AI disclaimer to the dprint PR |
bartlomieju
requested changes
Jun 1, 2026
bartlomieju
left a comment
Member
There was a problem hiding this comment.
Blocked on upstream plugin
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
A
TsUnionType(orTsIntersectionType) inside a${...}placeholder of aTsTplLitTypewas breaking only on the union separator (|/&) when the line exceeded the configured width, leaving the closing}glued onto the last union element's line.Reported in #29868. Minimal repro:
formatted to
instead of the expected
Fix
The fix is in
dprint-plugin-typescript(dprint/dprint-plugin-typescript#794): it addsTsUnionTypeandTsIntersectionTypeto theget_possible_surround_newlinesmatch insidegen_template_literal, so the existingsurround_with_newlines_indented_if_multi_linecodepath handles them the same way it already handlesBinExpr/CondExprplaceholders.Until the next
dprint-plugin-typescriptrelease ships that fix, this PR consumes it via a[patch.crates-io]against the fork branch. Once upstream releases a newdprint-plugin-typescriptversion with #794 merged, the[patch.crates-io]block inCargo.tomlshould be removed and thedprint-plugin-typescriptworkspace pin bumped to the released version.A spec regression test in
tests/specs/fmt/template_literal_type_unioncovers the case from the issue and asserts the expected formatted output.Closes #29868
Closes denoland/divybot#258
Test plan
cargo test specs::template_literal_type_uniontools/format.js && tools/lint.jsclean