Skip to content

Array destructuring emits non-nullable types #14727

Closed
@sberan

Description

@sberan

With strictNullChecks: true, nullable values are not emitted as a result of an array destructure. Any array destructure can potentially emit undefined values.

TypeScript Version: 2.2.1

Code

  const x:number[] = []
  const [y] = x
  y.toString()

Expected behavior:
Compile error on line 3: [ts] Object is possibly 'undefined'

Actual behavior:
Runtime error on line 3: Cannot read property 'toString' of 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