Closed
Description
π Search Terms
spread, destructuring, { ...[]}
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Destructuring
β― Playground Link
π» Code
const realArray: number[] = [1, 2, 3];
const fakeArray: number[] = { ...realArray };
// ^ I would expect TS to complain about this but for some reason it does not
console.log(`Based on typescript types 'realArray' is an array but is it really? ${Array.isArray(realArray)}`);
console.log(`Based on typescript types 'fakeArray' is an array but is it really? ${Array.isArray(fakeArray)}`);
realArray.pop() // works
fakeArray.pop() // π₯ fakeArray.pop is not a function
π Actual behavior
there is no TypeError when assigning { ...[]}
to a variable that is supposed to be an array based on the TS type
π Expected behavior
I would expect a type error like Type '{}' is missing the following properties from type 'number[]': length, pop, push, concat, and 26 more.
which happens when you try to assign { }
to a variable with an Array type
Additional information about the issue
I hope this is no duplicate or that I am missing something obvious but I was not able to find something related to this specific issue
Metadata
Metadata
Assignees
Labels
No labels