镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

"Types .. have no overlap" (2367) error when LHS generic type's constraint extends RHS generic type, new in 4.8 #50893

Closed

Description

Bug Report

🔎 Search Terms

2367 types overlap generic constraint

🕗 Version & Regression Information

This changed between versions 4.7.4 and 4.8.2.

⏯ Playground Link

Playground link with relevant code

💻 Code

class C<T> {
    constructor(readonly x: T) {}

    good<U extends T>(y: U) {
        if (y === this.x) {}
    }

    bad<U extends T | string>(y: U) {
        if (y === this.x) {} // <- OK in 4.7.4, error in 4.8.2
    }
}

🙁 Actual behavior

The code type-checks OK in 4.7.4.

In 4.8.2 error 2367 (types 'U' and 'T' have no overlap) is thrown on the if guard in bad().

🙂 Expected behavior

T | string includes T, so there is overlap between the two sides of the comparison, therefore the diagnostic seems to be incorrect.

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions