Skip to content

Comparing to string literals should be the same as comparing to consts of the same type #3262

@davidswinegar

Description

@davidswinegar

Paste the following into try flow:

// @flow

const stringLiteral: 'STRING' = 'STRING'

const test = (type: 'STRING' | 'NUM') => {
    if (type === stringLiteral) {
        (type: 'STRING') // does error, but should not.
    }
    if (type === 'STRING') {
        (type: 'STRING') // A-OK
    }
};

The above code errors, but it should not. The type of stringLiteral is the string literal 'STRING' (not string) and it cannot be changed, so comparisons should work the same as comparing to a string literal. However, it does not.

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