Skip to content

--strictNullChecks enforcing unnecessary tests #11095

@jice-nospam

Description

@jice-nospam

TypeScript Version: 2.0.3

Code
More a suggestion than a bug. I found out that there are a few situations where enabling strictNullChecks results in unnecessary complexity in the code. For example :

if ( myArray.length > 0 ) {
    let o: Object = myArray.pop();
    o.method();
}

Expected behavior:
should compile

Actual behavior:
requires a Object | undefined type and an additional safety test

if ( myArray.length > 0) {
    let o: Object | undefined = myArray.pop();
    if (o) {
        o.method();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions