You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constrealArray: number[]=[1,2,3];constfakeArray: number[]={ ...realArray};// ^ I would expect TS to complain about this but for some reason it does notconsole.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()// worksfakeArray.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
The text was updated successfully, but these errors were encountered:
π Search Terms
spread, destructuring, { ...[]}
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.3#code/MYewdgzgLgBATgUwIYBsCCc5IJ4C4ZgCuAtgEYJwDaAujALwyUCMANDAExsDM1A3AFChIsAGZIA1ggxY8BEuSq0GAbxgA6DYlTScMAL4CA9IZimz5i5bMA9GAEkYAdxCEUAExgIAHgAcEwWAAVAGUYKBAYUGIfFCQASzAYJFIXWCgACziIGFJCURA4GAgQYgR4ZGLEuNg3EARssBAofkFwYpQENRQQAHMACgADACEkCAQPcDDsPwhgODifNOn6mAByLXRMHFWYLKTEpC3sHLzd7Ory1BRsAH4YABJlHWw1LOe+jeeASj0Br4EhO1Ot1+sNRuMYJMoMtZvNFlMZmsxJJnjs9kgDkcTrA9hcNtc7o9nq8IO9kVIjj8-gJ+J8jmofCAfH0vjBjE4CuIIPxycTGczWezALwbgFKdmC8+n8s4EJpJcWEMABOKTIA
π» Code
π 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 typeAdditional 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
The text was updated successfully, but these errors were encountered: