Skip to content

Unexpected error: This comparison appears to be unintentional because the types '"yes"' and '"no"' have no overlap.(2367)Β #60586

Closed as not planned
@bpasero

Description

@bpasero

πŸ”Ž Search Terms

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

πŸ•— Version & Regression Information

This reproduces also in TS 5.6, 5.5.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYGwhgzhAEBiD29oG8BQ0MFMB2AXAlriJgLY64Bc0A5AJ6YTXQA+N28TAvDfY6gL6pUoSDABCYAE4ohGDAAdJ+AG5hcmaADNE0btkwB3OIgAUASllyA5plzRyhYmTzmZc99Em2ArpOzRcAAt8CAA6bXhQhyJScgBudDlBRIwAIylXNA85fE1oEyCQqLxHWLxdTm46BmozN2yPQrCI4oIY5zsq9moEho9c-KbW0o6Kro46rL6GlOnk6blgeGwIeGJQkHgrAuCw6KdyM16GwXdBZKWVu3TpPUNoCUlzBJvQm+fUIA

πŸ’» Code

class Foo {
   entitlement: 'yes' | 'no' = 'yes'
}

class Bar {

    private foo = new Foo()

    get entitlement() {
        return this.foo.entitlement;
    }

    bar() {
        if (this.entitlement === 'yes') {
            this.foo.entitlement = 'no';
            if (this.entitlement === 'no') {
          //^^^^^^^This comparison appears to be unintentional because the types '"yes"' and '"no"' have no overlap.(2367)                
            }

            console.log(this.entitlement);
        }
    }
}

const bar = new Bar();
bar.bar();

πŸ™ Actual behavior

The check in line 16 (if (this.entitlement === 'no') {) produces a compile error:

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

πŸ™‚ Expected behavior

The check in line 16 (if (this.entitlement === 'no') {) does not produce a compile error.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions