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
@yseymour

Description

@yseymour

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

Assignees

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