Skip to content

Fix formatting of long template parameter declarations - #11838

Draft
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:op-is-template-format-fix
Draft

Fix formatting of long template parameter declarations#11838
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
microsoft:mainfrom
timotheeguerin:op-is-template-format-fix

Conversation

@timotheeguerin

@timotheeguerin Timothee Guerin (timotheeguerin) commented Sep 2, 2026

Copy link
Copy Markdown
Member

Fixes #11836

A template parameter list with a single parameter was always "hugged", so it could never break. When the declaration got too long the constraint (or default) was split instead, leaving the > stranded in the middle of the line:

op deleteJobPreview<AreaPreviewLabel extends
  | FoundryFeaturesOptInKeys
  | AgentDefinitionOptInKeys> is FoundryDataPlanePreviewOperation<
  AreaPreviewLabel,
  NoContentResponse
>;

Now a single parameter is only hugged when it cannot break by itself. As soon as it has a breakable constraint or default, the parameter list breaks instead — like prettier does for TypeScript type parameters — and the union only splits when it still doesn't fit:

op deleteJobPreview<
  AreaPreviewLabel extends FoundryFeaturesOptInKeys | AgentDefinitionOptInKeys
> is FoundryDataPlanePreviewOperation<AreaPreviewLabel, NoContentResponse>;

op deleteJobPreview<
  AreaPreviewLabel extends
    | FoundryFeaturesOptInKeysExtraLongNeedSplit
    | FoundryFeaturesOptInKeysExtraLongNeedSplit
    | AgentDefinitionOptInKeys
> is FoundryDataPlanePreviewOperation<AreaPreviewLabel, NoContentResponse>;

Parameters that cannot break (<T>, <T extends TypeSpec.Reflection.Model>, <T = Foo>) keep hugging exactly as before, even when the line ends up over the print width, so existing specs are not reflowed for no reason.

The issue was not specific to op ... is: it applied to every construct that can declare template parameters — model (is/extends/body), alias, interface, ops inside an interface, union and scalar. All of them are covered by the new tests.

Template arguments are untouched, so the behavior from #11009 / #11092 (Foo<{...}> and long single unions staying attached to the reference) is unchanged.

Along the way this surfaced a small wart in the one place TypeSpec inlines a model expression — properties are now separated by ; instead of ;:

model Foo<
  T extends {someProperty: string; anotherProperty: string; thirdProp: int32}
> {}

Impact

Reformatting all 5054 .tsp files in Azure/azure-rest-api-specs with the current formatter changes 0 files; with this fix it changes 6, and every hunk is the broken shape above being repaired — preview PR.

@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler emitter:client:java Issue for the Java client emitter: @typespec/http-client-java labels Sep 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11838

commit: cd6fd76

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

[formatter] Split the template parameter list instead of splitting a parameter constraint or default when the declaration is too long,> ,> tsp,> // Before,> op deleteJobPreview<AreaPreviewLabel extends,> | FoundryFeaturesOptInKeys,> | AgentDefinitionOptInKeys> is FoundryDataPlanePreviewOperation<AreaPreviewLabel>;,> ,> // After,> op deleteJobPreview<,> AreaPreviewLabel extends FoundryFeaturesOptInKeys | AgentDefinitionOptInKeys,> > is FoundryDataPlanePreviewOperation<AreaPreviewLabel>;,>

@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Sep 2, 2026
@azure-sdk-automation

azure-sdk-automation Bot commented Sep 2, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Timothee Guerin (timotheeguerin) added a commit to timotheeguerin/azure-rest-api-specs that referenced this pull request Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler emitter:client:java Issue for the Java client emitter: @typespec/http-client-java meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird formatting in template

1 participant