Skip to content

strictNullChecks still allows to assign undefined to the variable declared as number #11238

Closed
@OleksandrNechai

Description

@OleksandrNechai

TypeScript Version: 2.0.0

Code

// strictNullChecks is on
var x: number[] = [];
var y: number = x[0];
y.toString(); // Cannot read property 'toString' of undefined

Expected behavior:
error TS2322: Type 'undefined' is not assignable to type 'number'

Actual behavior:
after compile with command tsc --strictNullChecks
Runtime exception: Cannot read property 'toString' of undefined

I thought strictNullChecks a there to prevent developer from seeing such kind of exceptions in run time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions