Skip to content

Code flow analysis isn't smart enough #8270

@pleerock

Description

@pleerock

typescript version: Version 1.9.0-dev.20160424

first looks like a bug:

if (options.leftJoin)
    Object.keys(options.leftJoin).forEach(key => {
        qb.leftJoin(options.leftJoin[key], key);
    });

Gives TS2531: Object is possibly 'null' or 'undefined'., however error is not expected because of the if (options.leftJoin) check above.
num1

second:

connect(options?: ConnectionOptions) {
    if (!options)
        options = {} as ConnectionOptions;

    console.log(options.url);
}

Gives same TS2531: Object is possibly 'null' or 'undefined'.. Looks like expected behaviour because of original type of the options object. Solution is to define variable with a new type and without undefined. Maybe there is a smarter way to do it?
num2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions