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
literal function with structure spread can't be rightly inferred in function's generic type slot #28816
For the getFoo function we end up using the type implied by the binding pattern (i.e. ({ foo }: { foo?: number }) => number) because there is no type annotation, contextual type, or initializer type. This is working as intended.
However, for the function expression passed as an argument to id we do have a contextual type, namely T. Since T has no constraint we should end up inferring an implicit any type for the parameter, but this isn't quite working correctly.
So, the bug here is that newGetFoo2 should have type ({ foo }: any) => any and in -noImplicitAny mode we should report an implicit any error on foo.
EDIT: In retrospect, I now agree newGetFoo2 should have the same type as getFoo and newGetFoo. #36476 has the fix.
Activity
ahejlsberg commentedon Jan 25, 2019
Our intended design is to determine the type of a parameter from one of the following, in order of preference:
See original discussion and rationale here.
For the
getFoofunction we end up using the type implied by the binding pattern (i.e.({ foo }: { foo?: number }) => number) because there is no type annotation, contextual type, or initializer type. This is working as intended.However, for the function expression passed as an argument to
idwe do have a contextual type, namelyT. SinceThas no constraint we should end up inferring an implicitanytype for the parameter, but this isn't quite working correctly.So, the bug here is that
newGetFoo2should have type({ foo }: any) => anyand in-noImplicitAnymode we should report an implicit any error onfoo.EDIT: In retrospect, I now agree
newGetFoo2should have the same type asgetFooandnewGetFoo. #36476 has the fix.ahejlsberg commentedon Jan 28, 2020
Fix in #36476 now produces the result expected in the original post.