Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bpasero opened this issue Nov 25, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@bpasero
Copy link
Member

bpasero commented Nov 25, 2024

πŸ”Ž 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

@MartinJohns
Copy link
Contributor

Duplicate of #9998.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 27, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants