Skip to content

Type guard does not affect variable inside a function #20901

@srolel

Description

@srolel

TypeScript Version: 2.7.0-dev.201xxxxx

Code

function foo(o: number | number[]) {
    if (!Array.isArray(o)) {
        o = [o];
    }
    o.length;
    () => o.length;
}

Expected behavior:
No compile errors.

Actual behavior:

Property 'length' does not exist on type 'number'.

in () => o.length

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