FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid duplicate assignability errors on literal unions by bodapatisaikrishna · Pull Request #64595 · microsoft/TypeScript · GitHub

Repository navigation

Avoid duplicate assignability errors on literal unions - #64595

Open
bodapatisaikrishna wants to merge 2 commits into
microsoft:mainfrom
bodapatisaikrishna:fix/double-error-union-literal-assignability
Open

bodapatisaikrishna wants to merge 2 commits into
microsoft:mainfrom
bodapatisaikrishna:fix/double-error-union-literal-assignability

Conversation

Copy link
Copy Markdown

Fixes #63050.

When relation error reporting generalizes a literal union to the same base type as its constituent check, the error chain ends up emitting the exact same assignability error twice. This elides the redundant child diagnostic when its arguments match the outer error.

When a union of literals generalizes to the same base type as its constituent check, elide the redundant child diagnostic on the error chain.

Fixes microsoft#63050.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:07
github-project-automation Bot moved this to Not started in PR Backlog Oct 2, 2026
typescript-automation Bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Oct 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 2

Open (2) What changed in this PR

Prevents redundant nested diagnostics when assignability checks on literal unions are generalized to the same base type, which previously caused the same assignability error to be emitted twice.

Changes:

  • Adds a compiler test case covering duplicate assignability errors for literal unions (string/number/bigint).
  • Adjusts relation error reporting to elide a redundant child diagnostic for assignability/comparability when it matches the outer diagnostic.
  • Updates multiple .errors baselines to reflect deduplicated error chains.
File Description
tsc/​internal/​checker/​relater.go Drops a redundant child entry from the error chain when assignability/comparability diagnostics match.
tsc/​testdata/​tests/​cases/​compiler/​literalUnionAssignabilityDoubleError.ts New regression test reproducing the duplicate-error scenario.
tsc/​testdata/​baselines/​reference/​compiler/​literalUnionAssignabilityDoubleError.errors.txt New baseline verifying only one assignability error is emitted per site.
tsc/​testdata/​baselines/​reference/​compiler/​literalUnionAssignabilityDoubleError.types New type baseline for the added test.
tsc/​testdata/​baselines/​reference/​compiler/​literalUnionAssignabilityDoubleError.symbols New symbol baseline for the added test.
tsc/​testdata/​baselines/​reference/​compiler/​literalUnionAssignabilityDoubleError.js New emit baseline for the added test.
tsc/​testdata/​baselines/​reference/​compiler/​typeOfOperator1.errors.txt Baseline updated to remove duplicated nested error line.
tsc/​testdata/​baselines/​reference/​compiler/​recursiveIndexedAccessSimplification.errors.txt Baseline updated to remove duplicated nested error segments.
tsc/​testdata/​baselines/​reference/​compiler/​complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt Baseline updated to remove repeated nested assignability chain lines.
tsc/​testdata/​baselines/​reference/​compiler/​bigintPropertyName.errors.txt Baseline updated to remove duplicated nested error line.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/checker/relater.go Outdated
}
case diagnostics.Type_0_is_not_assignable_to_type_1,
diagnostics.Type_0_is_not_comparable_to_type_1:
if r.chainArgsMatch(generalizedSourceType, targetType) {
Comment thread tsc/internal/checker/relater.go Outdated
Comment on lines +4860 to +4864
case diagnostics.Type_0_is_not_assignable_to_type_1,
diagnostics.Type_0_is_not_comparable_to_type_1:
if r.chainArgsMatch(generalizedSourceType, targetType) {
r.errorChain = r.errorChain.next
}

This branch has not been deployed

No deployments
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

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Double error message when referencing variable of type union of string literals from ambient declaration

2 participants


Back | FazBrowse Home | New Git URL