Skip to content

Unexpected TS2365: Build:Operator '==' cannot be applied to types 'true' and 'false' #12772

@sgreer

Description

@sgreer

After updating to TypeScript 2.1, I am receiving an error when compiling a project that compiled under TS 2.0.

Below is the snippet of code that produces the error.

var id1 = true, id2 = true;
$(selector, $(question)).each((i, iteminput) => {
    $id = $(iteminput);
    id = $id.attr("id");
    if (!$id.is(":checked") && $id.is(":visible") && $id.data("val-required") == "Required") {
        if (i == 0)
            id1 = false;
        else if (i == 1)
            id2 = false;
    }
});
if (id1 == false && id2 == false) {
    valid = false;
    this.showValidationPrompt({
        message: "* This question is required.",
        elementid: id,
        placement: 0,
        promptType: 1,
        containerSelector: ".cq-wrapper .cq-input"
    });
}

Expected behavior: That this snippet will compile without errors.

Actual behavior: I receive the following error message:

error TS2365: Build:Operator '==' cannot be applied to types 'true' and 'false'.

due to this condition evaluation:

if (id1 == false && id2 == false) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions