Skip to content

RHS expression type in assignment incorrectly inferred #3123

Closed
@yjbanov

Description

@yjbanov

To completely fix #1587 TypeScript should also support:

function repro(message: Object | Object[]) {
    if (message instanceof Array) {
        message = message.filter;  // error
    }
}

Currently it results in Property 'entries' does not exist on type 'Object | Object[]'. It seems message on the RHS switches from Array back to Object | Object[] prematurely.

Workaround:

function workaround(message: Object | Object[]) {
    var theMessage = message;
    if (theMessage instanceof Array) {
        message = theMessage.filter;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions