Skip to content

Error with strictNullChecks when destructuring. #9341

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

Closed
rbuckton opened this issue Jun 24, 2016 · 0 comments
Closed

Error with strictNullChecks when destructuring. #9341

rbuckton opened this issue Jun 24, 2016 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rbuckton
Copy link
Member

Given the following TypeScript:

const a: { x?: number; } = { };
let x = 0;
({ x = 1 } = a); // error: Type 'number | undefined' is not assignable to 'number'.

However, the destructuring assignment has a default value assigned. This should be treated the same way that strict null checking treats VariableDeclarationList, which does not have this error:

const a: { x?: number; } = { };
let { x = 1 } = a; 
let y: number = x; // ok, x has type 'number'

TypeScript Version:
nightly

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Jun 24, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jun 28, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jun 30, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants