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
{{ message }}
Repository navigation
Generic inference from LHS of assignment when destructuring can lead to unexpected anys Β #45074
declarefunctiongenericFunc<T>(): T;const{ bar }=genericFunc();// `bar` is `any` here.
π Actual behavior
bar is any and T is inferred to be { bar: any }.
π Expected behavior
The inferred type of T should be unknown and there should be an error from trying to destructure it.
(Or, T could still be inferred as { bar: any } but then noImplicitAny 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!)
The inference of { bar: any } may or may not be avoidable without breaking a lot of other inferences, but it should at least error under noImplicitAny.
Yeah. Probably not going to fix the noImplicitAny error for 4.5 because I want to investigate making this whole pattern an error in the 4.6 timeframe, as discussed in that design meeting.
Activity
andrewbranch commentedon Jul 21, 2021
The inference of
{ bar: any }may or may not be avoidable without breaking a lot of other inferences, but it should at least error undernoImplicitAny.andrewbranch commentedon Jul 21, 2021
Related: #43605
jkillian commentedon Oct 1, 2021
Related to the discussion in #46012 I believe
andrewbranch commentedon Oct 4, 2021
Yeah. Probably not going to fix the
noImplicitAnyerror for 4.5 because I want to investigate making this whole pattern an error in the 4.6 timeframe, as discussed in that design meeting.jkillian commentedon May 24, 2022
Love that this is fixed, thanks Andrew Branch (@andrewbranch)!