Skip to content

Unexpected "Object is possibly undefined" error #17240

Description

TypeScript Version: 2.3.4

Code

const foo = (bar?: { baz: number }) => {
    if (bar == null) {
        bar = { baz: 0 };
    }
    const baz = () => {
        console.log(bar.baz); // Object is possibly undefined
    };
    baz();
};

Playground link

Expected behavior:
No error

Actual behavior:
Error "Object is possibly undefined"

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