Skip to content

Excess properties check does not occur for object literals in conditional expressions #12938

Closed
@Knagis

Description

@Knagis

TypeScript Version: 2.1.4 / 2.1.4-insiders.20161201

Code

Code on playground

interface IFoo {
    foo?: number;
    bar?: number;
}

let a: IFoo = {
    foo: 1,
    asd: 2 // this line shows error
};

let b = true;
let c: IFoo =
    b ? {
        asd: 2 // this line shows error
    } : {
        foo: 1,
        asd: 2 // this line does NOT show an error
    }

Also this version fails:

let c: IFoo =
    b ? {
    } : {
        foo: 1,
        asd: 2 // this line does NOT show an error
    }

Expected behavior:
All asd:2 assignments should show an error

Actual behavior:
Only the first two show the error, the last one does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions