Closed
Description
TypeScript Version: 3.7.x-dev.201xxxxx
array with push inference failing
Code
const Foo = (arg: { val: number }[]) => {
return { val: 1 }
}
let arr = []
arr.push({
bar: 1, // ERROR: argument of type X is not assignable to parameter of type Y, etc.
...Foo([]),
})
Foo(arr) // comment out this and uncomment below
// this circumvents the error
// let lol = arr; Foo(lol)
Expected behavior:
Typescript should be able to guess the array type when spreading out {val: 1} to be {bar: number, val: number}[]
.
Actual behavior:
It errors with a confusing error. It's circumventable by doing let lol = arr; Foo(lol)
Playground Link:
Playground Link
Related Issues:
Not really sure what to search for.