Skip to content

Comparing these two incomparable types does not lead to an error #7402

Open
@lll000111

Description

@lll000111

No error from this code comparing two incompatible types:

Flow Try Link

function demo (someString: string, someArray: Array<number>): void {
    // ERROR EXPECTED - none received
    if (someArray === someString) {
        // ...
    }
}

someArray can also be some other type, such as number (arguable, if it was "==" instead of "===") or some object type (definitely useless, comparison to a pointer), it does not have to be an array.


My take:

If the types are known I would expect them to be enforced, only an unknown or yet-to-be-refined type should be comparable to (at that point potentially) incompatible types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions