Skip to content

Closure error TS2532 #21162

@ghost

Description

TypeScript Version: 2.6.2 | 2.7.0-dev.20180112

Code

// test.ts
function foo(map: Map<string, string>) {
    let bar = map.get('key');
    if (!bar) {
        return;
    }

    let res1 = bar.repeat(3);

    let fun = () => {
        let res2 = bar.repeat(3);
    }
}

Expected behavior:
no errors

Actual behavior:
test.ts(11,20): error TS2532: Object is possibly 'undefined'.

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