Skip to content

Spreading an array inside an object where an array is expected doesn't cause a type error #49667

Closed
@lucaslcode

Description

@lucaslcode

Bug Report

🔎 Search Terms

destructure, spread, object, array

🕗 Version & Regression Information

Using 4.5.5 but also in nightly playground

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

⏯ Playground Link

Playground link with relevant code

💻 Code

type MyType = {test: string}

const list: MyType[] = [{test: "a"}, {test: "b"}];

const x: Record<string, MyType[]> = {
  // object shouldn't be allowed?
  "hello": {
    ...list
  }
}

console.log(x);
x["hello"].map((el) => el);
// map doesn't exist on object

🙁 Actual behavior

Spreading an array inside an object where an array is expected works, and the type information is then incorrect.

🙂 Expected behavior

Spreading an array inside an object where an array is expected should give a type error.

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