Skip to content

Spreading array to object not typing correctly #54207

Closed
@tcK1

Description

@tcK1

Bug Report

🔎 Search Terms

Spread, Spreading, Array, Object, Destruct, Destructuring

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Spreading an array to an Object.

⏯ Playground Link

Playground Link

💻 Code

const a = [1, 2, 3];
const b = { ...a };
b.pop();

🙁 Actual behavior

TS did not show that .pop() did not exist in the new variable. The new variable type has "all the properties" from the array, including the prototype functions. I guess that's why it failed to show that the function doesn't exist.

Example of the code failing:

🙂 Expected behavior

It should show values from the Object prototype and not from Array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions