Skip to content

TS2367: This condition will always return 'false' #29822

Closed
@lonereck

Description

@lonereck

TypeScript Version: 3.3.3

Search Terms: TS2367

class Scanner {
    private _index: number;
    private _input: string;

    public get current() { 
        return this._input[this._index];
    }

    constructor(input: string) {
        this._input = input;
        this._index = 0;
    }

    public Scan() {
        if (this.current == "A") {
            this._index++;
            // error TS2367: This condition will always return 'false' since the types '"A"' and '"B"' have no overlap.
            if (this.current == "B") {
                // do something
            }
        }
    }
}

Expected behavior:
No compilation errors

Actual behavior:
error TS2367: This condition will always return 'false' since the types '"A"' and '"B"' have no overlap.

Playground Link:
Here

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