Skip to content

Object spread should not exclude setter-only properties #26337

@ajafff

Description

@ajafff

TypeScript Version: 3.1.0-dev.20180808

Search Terms:

Code

const obj = {
    foo: 1,
    ...{set bar(v: number) {}}
};

Expected behavior:

obj is inferred as {foo: number, bar: undefined}.
Spreading a setter-only property uses undefined as the property's value.
Likewise the following evaluates to true:

({
    foo: 1,
    ...{set foo(v) {}}
}).foo === undefined;

Actual behavior:

obj is inferred as {foo: number}.

Playground Link: https://agentcooper.github.io/typescript-play/#code/MYewdgzgLgBCBGArGBeGBvAUDHMBmIIAXDAIwA02uAdLehAKazwCGATgBQBuJYArgFt4DNgEoMAXwmYJAbkxA

Related Issues:
#11596
#21759
#17793

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