Skip to content

Narrowing union types with array's indexOf #9842

Closed
@normalser

Description

@normalser

It would be great if TS could handle this:

                if (typeof reply == 'string') {

                }
                else if (~['input', 'button'].indexOf(reply.typeName)) {
                    const test = reply // Input or Button - currently everything
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions