Skip to content

Error with strictNullChecks when destructuring. #9341

@rbuckton

Description

@rbuckton

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions