镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Error with strictNullChecks when destructuring. #9341

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

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