Skip to content

Fix TS2367 false positive when comparing generic constructor types with concrete constructors - #64865

Closed
RXVEN-1907 (RXVEN-1907) wants to merge 1 commit into
microsoft:mainfrom
RXVEN-1907:rxven/typescript
Closed

RXVEN-1907 (RXVEN-1907) wants to merge 1 commit into
microsoft:mainfrom
RXVEN-1907:rxven/typescript

Conversation

@RXVEN-1907

Copy link
Copy Markdown

When comparing a generic constructor type against a concrete constructor, the checker reports TS2367 even though the comparison is valid: func(Child) in the linked issue accepts Child as Constructor<T>, so constructor === Child can legitimately be true. Reproduced on current main (7.1.0-dev) and on typescript@7.0.2: if (constructor === Child) fails with "the types 'Constructor' and 'typeof Child' have no overlap".

The comparable relation already treats a type parameter appearing as the source as comparable through its constraint, but when a free type parameter appears as the target of a comparison (here: Base<T>.Item: T inside the constructor's return type), a non-type-parameter source is reported as having no overlap. That asymmetry only becomes visible when the type parameter is nested inside a property or a construct signature return type, because there the top-level equality check never retries in the other direction.

This change adds the mirrored fallback: under the comparable relation, when the target is an unconstrained type parameter (its constraint is unknown), a non-type-parameter source is also checked against unknown, so it is treated as potentially overlapping. Type parameters with an object constraint keep their current strict behavior, so the existing TS2352/TS2367 expectations in genericTypeAssertions4/5 and unknownControlFlow are unchanged.

I added tests/cases/compiler/comparableRelationTypeParameterTarget.ts with its generated baseline, and ran the full go test ./... suite under tsc/ locally with no failures.

Disclosure: this PR was prepared with AI assistance and reviewed by me.

Fixes #27910

…th concrete constructors

Signed-off-by: RXVEN-1907 <viswajeet2502@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:04
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 19, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Oct 19, 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.

🟢 Approval recommended

Static review identified no blocking issues in the narrowly guarded fallback or regression baselines; tests were not run during this review.

No open issues 🎉

What changed in this PR

Fixes #27910 by allowing valid comparisons between generic constructor types and concrete constructors in the native TypeScript checker.

Changes:

  • Adds a comparable-relation fallback for unconstrained target type parameters.
  • Adds regression coverage for constructor comparisons while preserving errors for unrelated type parameters.
File Description
tsc/​internal/​checker/​relater.go Adds the guarded comparability fallback.
tsc/​testdata/​tests/​cases/​compiler/​comparableRelationTypeParameterTarget.ts Tests valid constructor and invalid unrelated-parameter comparisons.
tsc/​testdata/​baselines/​reference/​compiler/​comparableRelationTypeParameterTarget.types Records expected types.
tsc/​testdata/​baselines/​reference/​compiler/​comparableRelationTypeParameterTarget.symbols Records expected symbols.
tsc/​testdata/​baselines/​reference/​compiler/​comparableRelationTypeParameterTarget.errors.txt Records the remaining expected TS2367 diagnostic.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.

2 participants