Skip to content

Spreading private property is wrong #27166

Open
@ghost

Description

TypeScript Version: 3.1.0-dev.20180914

Code

class C {
    constructor(readonly x: number, private readonly y: number) {}
}
const a = { ...(new C(0, 1)) };
const b = { x: "", y: "", ...a };
b.x.toUpperCase(); // Error (good)
b.y.toUpperCase(); // No error (bad)

Expected behavior:

Error at the spread since that accesses a private property.
At least there should be an error at b.y since that accesses the same private property, and is a number at runtime.

Actual behavior:

No error except at b.x.toUpperCase() which is correctly an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions