Skip to content

fix: Incorrect type resolution with nested constructors#63670

Open
thiagobarbosa wants to merge 1 commit into
microsoft:mainfrom
thiagobarbosa:fix/type-resolution-with-nested-constructor
Open

fix: Incorrect type resolution with nested constructors#63670
thiagobarbosa wants to merge 1 commit into
microsoft:mainfrom
thiagobarbosa:fix/type-resolution-with-nested-constructor

Conversation

@thiagobarbosa

Copy link
Copy Markdown

Fixes #63559

Problem

When a class extends a value whose type is a class instance carrying its own new construct signature, the checker
incorrectly resolved the base type using the instance type of the extended class symbol, instead of resolving it
from the construct signature. This caused the base type to be computed as the wrong (outer) instance type instead
of the type actually returned by the constructor.

Fix

In getBaseTypeOfClassOrInterface constructor-type resolution logic (src/compiler/checker.ts), the fast path that
reuses originalBaseType (the declared type of the base constructor's symbol) is now skipped when
baseConstructorType is not itself equal to originalBaseType — i.e., when the base constructor type is an instance
type sharing the class symbol, rather than the constructor itself. In that case, the base type is instead resolved
from the construct signatures, as intended.

Testing

Added tests/cases/compiler/classExtendsConstructorReturningConstructor.ts, which reproduces the issue: a class
extending a value with a nested new signature returning another type with its own nested new signature. Verifies
that kind resolves to "A" and "B" correctly at each nesting level (baselines: .types and .symbols).

Resolves microsoft#63559
microsoft#63559

Generated by issue-coder. Review before pushing.
Copilot AI review requested due to automatic review settings July 22, 2026 18:16
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jul 22, 2026
@typescript-automation typescript-automation Bot added For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 22, 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.

Pull request overview

Fixes an edge-case in class base-type resolution where extends targets that are class instance types with construct signatures were incorrectly treated as if their construct signatures always returned the class instance type, causing the “outer” instance type to repeat instead of following the constructor return type chain (as in #63559).

Changes:

  • Adjusted the “fast path” in resolveBaseTypesOfClass (src/compiler/checker.ts) to avoid reusing the declared instance type when the base constructor type is actually the class instance type.
  • Added a new compiler test that reproduces nested-new() constructor-return behavior.
  • Added .types and .symbols baselines validating the corrected resolution at each nesting level.

Reviewed changes

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

File Description
src/compiler/checker.ts Skips the class fast-path when the base “constructor type” is actually the class instance type, forcing resolution via construct-signature return types.
tests/cases/compiler/classExtendsConstructorReturningConstructor.ts New repro test for nested constructor-return chains in extends expressions.
tests/baselines/reference/classExtendsConstructorReturningConstructor.types Baseline confirming kind resolves to "A" then "B" at the correct nesting levels.
tests/baselines/reference/classExtendsConstructorReturningConstructor.symbols Baseline confirming symbol binding aligns with the intended nested constructor-return resolution.

@thiagobarbosa

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Incorrect type resolution with nested constructors

2 participants