Skip to content

array spread into an object is incorrectly assignable to array types #48692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DetachHead opened this issue Apr 14, 2022 · 1 comment
Closed

Comments

@DetachHead
Copy link
Contributor

Bug Report

🔎 Search Terms

spread object assignable to array

🕗 Version & Regression Information

Playground link with relevant code

💻 Code

const foo: string[] = []

//error: Type '{}' is missing the following properties from type 'string[]': length, pop, push, concat, and 26 more.
const bar: string[] = {}

//no error
const baz: string[] = {...foo}

//runtime error because its not an array
bar.push("")

🙁 Actual behavior

object is assignable to an array type

🙂 Expected behavior

error because the object does not have all the members of Array

@MartinJohns
Copy link
Contributor

Duplicate of #43977. Used search terms: object spread array in:title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants