Skip to content

"Types .. have no overlap" (2367) error when LHS and RHS generics both extend same constraintΒ #51584

Closed
@yseymour

Description

@yseymour

Bug Report

πŸ”Ž Search Terms

2367 types overlap

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Base { x: number }

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

    foo<U extends Base>(y: U) {
        if (y === this.x) {}  // <-- error: 'U' and 'T' have no overlap
    }
}

πŸ™ Actual behavior

An error is raised on the if clause.

This comparison appears to be unintentional because the types 'U' and 'T' have no overlap.(2367)

πŸ™‚ Expected behavior

Both U and T are constrained by Base, so they conceivably could overlap, so comparing them should be OK (and as a side-effect, it'd be nice if the comparison also refined U to T inside the if block).

maybe related: #50893 (PR: #50978)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions