Describe the bug
When a union is passed directly as a template argument (e.g. PickProperties<T, "a" | "b" | ...>) and the template argument list is long enough to wrap to multiple lines, tsp format inserts a blank line after the preceding argument and over-indents the union variants. The result looks unbalanced/broken compared to the surrounding code.
Note: a short union that fits on one line does not reproduce this — the template arguments must exceed the print width and wrap.
Reproduction
model Sample {
alpha: string;
bravo: string;
charlie: string;
delta: string;
echo: string;
foxtrot: string;
golf: string;
hotel: string;
}
model Picked is PickProperties<Sample, "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel">;
Run tsp format on the above.
Actual
model Picked
is PickProperties<
Sample,
| "alpha"
| "bravo"
| "charlie"
| "delta"
| "echo"
| "foxtrot"
| "golf"
| "hotel"
>;
Note the empty line after Sample, and the extra indentation applied to the leading-| union variants (they are indented one level deeper than the Sample argument).
Expected
No blank line, and the union variants aligned to the same indentation as the other template arguments, e.g.
model Picked is PickProperties<
Sample,
| "alpha"
| "bravo"
| "charlie"
| "delta"
| "echo"
| "foxtrot"
| "golf"
| "hotel"
>;
(exact wrapping is up to the formatter, but there should be no inserted blank line and no extra indent level for the union)
Checklist
Workaround
Extracting the union into an alias avoids the broken formatting, since the template argument becomes a single reference:
alias PickedKeys =
| "alpha"
| "bravo"
| "charlie"
| "delta"
| "echo"
| "foxtrot"
| "golf"
| "hotel";
model Picked is PickProperties<Sample, PickedKeys>;
Describe the bug
When a
unionis passed directly as a template argument (e.g.PickProperties<T, "a" | "b" | ...>) and the template argument list is long enough to wrap to multiple lines,tsp formatinserts a blank line after the preceding argument and over-indents the union variants. The result looks unbalanced/broken compared to the surrounding code.Note: a short union that fits on one line does not reproduce this — the template arguments must exceed the print width and wrap.
Reproduction
Run
tsp formaton the above.Actual
Note the empty line after
Sample,and the extra indentation applied to the leading-|union variants (they are indented one level deeper than theSampleargument).Expected
No blank line, and the union variants aligned to the same indentation as the other template arguments, e.g.
(exact wrapping is up to the formatter, but there should be no inserted blank line and no extra indent level for the union)
Checklist
@typespec/compiler1.13.0|printing inpackages/compiler/src/formatter/print/printer.ts.Workaround
Extracting the union into an
aliasavoids the broken formatting, since the template argument becomes a single reference: