Skip to content

Excess properties in object literals are allowed  #13444

Closed
@johnnyreilly

Description

@johnnyreilly

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

interface TheAllowedProperties { 
    iAmAllowed: boolean;
}

interface TheAllowedPropertiesAndThenSome { 
    iAmAllowed: boolean;
    thenSome: string
}

function doStuff(props: TheAllowedProperties) { 
    // do that thing you do
}

// 1. Errors - yay!!!! So, so very happy
doStuff({
    iAmAllowed: true,
    iAmNot: "surprise!"
})

// 2. Does not error - huh?  befuddlement....
const stuffWhatIPreparedEarlier = {
    iAmAllowed: true,
    iAmNot: "surprise!"
};

doStuff(stuffWhatIPreparedEarlier);

// 3. Also does not error - huh?  yet more befuddlement....
const moStuff: TheAllowedPropertiesAndThenSome = {
    iAmAllowed: true,
    thenSome: "other data that isn't relevant"
};

doStuff(moStuff);

Expected behavior:
I would have expected the compiler to complain in cases 2 and 3 above as they do in case 1. This might be the same as #7547 but the issue does not appear to be identical and so I wanted to double check. suppressExcessPropertyErrors is false

Actual behavior:
Cases 2 and 3 are not treated as errors.

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