Skip to content

Error "Operator '===' cannot be applied to types" with enum type #11533

@pltnkv

Description

@pltnkv

TypeScript Version: 2.0.3

Code

enum SomeEnum {
    V1,
    V2
}

class SomeClass {
    protected state:SomeEnum

    method() {

        // "Operator '===' cannot be applied to types 'SomeEnum.V1' and 'SomeEnum.V2'." error here
        this.state = SomeEnum.V1
        if (this.state === SomeEnum.V2) {
        }        

        // and the same error here
        if (SomeEnum.V1 === SomeEnum.V2) {
        }

        // but no error here
        let state2 = SomeEnum.V1
        if (state2 === SomeEnum.V2) {
        }
    }
}

Expected behavior:
I didn't expect that error in these cases

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