TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open yseymour opened this issue 3 years ago • 0 comments

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.

yseymour avatar Sep 22 '22 01:09 yseymour