-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue