Skip to content

Warn on unused property in object literal with spread #23340

@ghost

Description

TypeScript Version: 2.9.0-dev.20180411

Search Terms: object spread unused property

Code

interface Point { x: number; y: number; }
function withX(p: Point, x: number): Point {
    if (something) {
        return { x, x: p.x, y: p.y }; // Error
    } else {
        return { x, ...p }; // No error
    }
}

Expected behavior:

Error at { x, ...p }: The first x is dead because ...p has its own non-optional x.

Actual behavior:

No error at { x, ...p }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions