Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array destructuring emits non-nullable types #14727

Closed
sberan opened this issue Mar 19, 2017 · 2 comments
Closed

Array destructuring emits non-nullable types #14727

sberan opened this issue Mar 19, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@sberan
Copy link

sberan commented Mar 19, 2017

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

@sberan sberan changed the title Array destructuring emits nullable types Array destructuring emits non-nullable types Mar 19, 2017
@jesseschalken
Copy link
Contributor

See #11122 and related issues.

@sberan
Copy link
Author

sberan commented Mar 19, 2017

Thanks

@sberan sberan closed this as completed Mar 19, 2017
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 20, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants