Skip to content

Type checking stops after spread operatorοΏ½?#47995

Closed

Description

Bug Report

πŸ”Ž Search Terms

spread
spread operator
spread any
spread object assign

πŸ•— Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about the spread operator

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const x: any = { a: 5 }

interface I {
  b?: string
}

let spread: I;
spread = {
  ...x,
  b: 5
}

πŸ™ Actual behavior

Type mismatch is missed after use of spread operator.

πŸ™‚ Expected behavior

I expect a "Type 'number' is not assignable to type 'string | undefined'.(2322)" error for b: 5.

Similar bug #46128 indicates that after spread the type is not kept.
The main difference between the bugs is that in this case, the type is declared beforehand.


Edit: removed a line of code and changed some wording to make things clearer

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions