Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Knagis opened this issue Dec 15, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@Knagis
Copy link
Contributor

Knagis commented Dec 15, 2016

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.

@DanielRosenwasser DanielRosenwasser changed the title Known properties check for object literal does not work with conditional assignment Excess properties check does not occur for object literals in conditional expressions Dec 15, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 15, 2016

This is another manifestation of #12745. the result of the conditional operator is a union type, and thus the excess property check is ignored.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 15, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants