Skip to content

Fix off-by-one truncation in union type display#3658

Merged
gabritto merged 2 commits intomicrosoft:mainfrom
Andarist:fix/union-truncating
Apr 29, 2026
Merged

Fix off-by-one truncation in union type display#3658
gabritto merged 2 commits intomicrosoft:mainfrom
Andarist:fix/union-truncating

Conversation

@Andarist
Copy link
Copy Markdown
Contributor

fixes #3647

Copilot AI review requested due to automatic review settings April 29, 2026 09:48
@@ -380,11 +380,12 @@ func (b *NodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.Nod
result := make([]*ast.Node, 0, len(list))

for i, t := range list {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a behavioral mismatch in tsgo’s type display truncation logic (notably affecting TS7053 diagnostics) by correcting an off-by-one in the “... N more ...” elision calculation and adding a regression test to lock in the expected output.

Changes:

  • Fix off-by-one logic in NodeBuilderImpl.mapToTypeNodes when emitting truncated type lists (union/intersection/type-arg lists).
  • Add a new compiler test case covering union element error truncation.
  • Update affected reference baselines (compiler, fourslash quick info, and a submodule baseline) to reflect the corrected display output.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/nodebuilderimpl.go Fixes the truncation/elision count calculation and the truncation trigger condition for type list rendering.
testdata/tests/cases/compiler/unionElementErrorTruncation.ts Adds a regression test that reproduces the union truncation count mismatch seen in #3647.
testdata/baselines/reference/compiler/unionElementErrorTruncation.errors.txt New expected diagnostic output for the new regression test.
testdata/baselines/reference/compiler/unionElementErrorTruncation.js New expected emit baseline for the new regression test (includes .d.ts section due to @declaration: true).
testdata/baselines/reference/compiler/unionElementErrorTruncation.symbols New expected symbols baseline for the new regression test.
testdata/baselines/reference/compiler/unionElementErrorTruncation.types New expected types baseline for the new regression test.
testdata/baselines/reference/fourslash/quickInfo/quickinfoVerbosityNoErrorTruncation1.baseline Updates quickinfo truncation text to reflect corrected “... N more ...” counts.
testdata/baselines/reference/submodule/compiler/declarationEmitPrivatePromiseLikeInterface.js Updates a declaration emit baseline affected by the adjusted truncation behavior.
testdata/baselines/reference/submodule/compiler/declarationEmitPrivatePromiseLikeInterface.js.diff Updates the corresponding .diff baseline for the same truncation-related output change.

@gabritto gabritto added this pull request to the merge queue Apr 29, 2026
Merged via the queue into microsoft:main with commit ce43ebc Apr 29, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavior difference: TS7053 union count is slightly off in tsgo

3 participants