Skip to content

Handle recursive aliases in named tuple rest elements#4444

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-issue-63584
Open

Handle recursive aliases in named tuple rest elements#4444
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-issue-63584

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This addresses microsoft/TypeScript#63584.

Recursive aliases using named tuple rest elements like ...tagged: T[] were being treated differently from structurally equivalent unnamed rest elements, producing a spurious TS2456 circularity error.

  • Root cause

    • Alias deferral for tuple elements handled RestType specially, but missed the ArrayType nested under NamedTupleMember.
    • As a result, ...name: T[] could force eager alias resolution where ...T[] would defer.
  • Checker change

    • Teach mayResolveTypeAlias to recurse through ArrayType nodes.
    • This makes named tuple rest members participate in the same deferral path as ordinary rest tuple elements.
  • Regression coverage

    • Add a compiler test covering both recursive forms:
      • named rest in the first recursive tuple branch
      • named rest in a later tuple position
export type NamedRestDocNode1 =
    | string
    | ["i", ...tagged: NamedRestDocNode1[]]
    | ["li", index: number, ...NamedRestDocNode1[]];

export type NamedRestDocNode2 =
    | string
    | ["i", ...NamedRestDocNode2[]]
    | ["li", index: number, ...tagged: NamedRestDocNode2[]];

Copilot AI and others added 5 commits June 25, 2026 15:43
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@RyanCavanaugh RyanCavanaugh requested a review from weswigham June 25, 2026 16:07
@RyanCavanaugh RyanCavanaugh added this to the Post-7.0 milestone Jun 25, 2026
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review June 25, 2026 16:07
Copilot AI review requested due to automatic review settings June 25, 2026 16:07

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.

Pull request overview

This PR fixes a checker circularity regression where recursive type aliases using named tuple rest elements (e.g. ...tagged: T[]) could trigger a spurious TS2456 circular reference error, despite being structurally equivalent to unnamed rest elements.

Changes:

  • Extend Checker.mayResolveTypeAlias to recurse into ArrayType element types, matching the existing deferral behavior already applied to RestType wrapping an array.
  • Add a compiler regression test covering recursive aliases with both unnamed and named tuple rest members (named rest in the first branch and in a later tuple position).
  • Add new reference baselines (.types, .symbols, .js) for the new test.
Show a summary per file
File Description
internal/checker/checker.go Makes alias-resolution deferral logic see through ArrayType nodes so named tuple rest members don’t force eager alias resolution.
testdata/tests/cases/compiler/issue63584NamedTupleRestCircularReference.ts New regression test for recursive aliases with named vs unnamed tuple rest elements.
testdata/baselines/reference/compiler/issue63584NamedTupleRestCircularReference.types Expected type baseline for the new regression test.
testdata/baselines/reference/compiler/issue63584NamedTupleRestCircularReference.symbols Expected symbol baseline for the new regression test.
testdata/baselines/reference/compiler/issue63584NamedTupleRestCircularReference.js Expected JS baseline for the new regression test.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

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.

3 participants