Skip to content

Object spread can lead to unknown properties added [Regression v3.1.6] #32495

@Cellule

Description

@Cellule

TypeScript Version: 3.6.0-dev.20190719

Search Terms:
spread
type check

Code

// Error as expected, b2 is not a valid key
const foo: {a?: string; b?: string} = {
    //a: "",
    ...{b2: ""}
}
// I meant to overwrite b, but somehow this is accepted
const bar: {a?: string; b?: string} = {
    a: "",
    ...{b2: ""}
}

Expected behavior:
bar should not accept ...{b2: ""}

Actual behavior:
bar has type {a?: string; b?: string}, but at runtime actually has extra property b2

Playground Link:
No problem v3.0.1
Regression v3.1.6

Related Issues:
#30129

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptWorking as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions