deno
82284522 - fix(fmt): surround template literal type unions with newlines when too long

Commit
184 days ago
fix(fmt): surround template literal type unions with newlines when too 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>
Author
Parents
Loading