Generic inference from LHS of assignment when destructuring can lead to unexpected any
s
#45074
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
π Search Terms
Generic inference, destructuring, binding patterns
π Version & Regression Information
Exists in 4.3.5
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
bar
isany
andT
is inferred to be{ bar: any }
.π Expected behavior
The inferred type of
T
should beunknown
and there should be an error from trying to destructure it.(Or,
T
could still be inferred as{ bar: any }
but thennoImplicitAny
should trigger an error. This seems at a glance less desirable to me than the former, but I don't know enough how generic inference works to make a more informed recommendation. Anyways, some sort of error no matter how it happens is what would be ideal!)Notes: see #43371 (comment) for the original context.
The text was updated successfully, but these errors were encountered: