Skip to content

Error using intersection type for object rest destructuring #12520

Closed
@billti

Description

@billti

This is using the latest release-2.1 branch. I'm unclear why types B & C would behave differently below when it comes to object rest members, so I am assuming this is a bug. (ping @sandersn & @mhegazy ).

interface A {
    name: string;
    age: number;
}

interface B extends A {
    address: string;
}

type C = A & {address: string};

// Both v1 & v2 appear to have the same members...
var v1: B;
var v2: C;

// ... and assignment in either direction is fine
v1 = v2; // OK
v2 = v1; // OK

// let {name, ...x2} = v1;  // This line is valid (when uncommented)
let {name, ...x3} = v2;  // This line gives the error: Rest types may only be created from object types.

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