Skip to content

Spread operator should declare members as undefined for null or undefined objects  #13066

@stephanedr

Description

@stephanedr

TypeScript Version: 2.1.4 & 2.2.0-dev.20161220

Code

function test(t?: { a: number } | null): void {
    let b = { ...t };  // b: { a: number }
    let c: number = b.a;  // no error
}

Expected behavior:
b.a to be number | undefined, as if t is null or undefined, b is an empty object.
Actual behavior:
b.ais number.

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