-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better implicit function expression #25501
Comments
Your assumption is that the initial argument type infers the return of the function. That is not a valid assumption. For example, the following is totally valid: const fn = x => 2; But the type of What about: const fn = (x, y) => y; Again, totally valid. There simply is not sufficient information to reliably infer a return type for functions authored this way. TypeScript is good, but it cannot read minds of the developers (yet). |
@kitsonk Simple, just make
Actually, my assumption is that initial arguments will be used ( |
Actually, looking a little closer, it seems more like this is an ask for non-local type inference, not making unannotated functions generic. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Search Terms
Suggestion
Given this code:
Currently, it is translated to:
But I think this would be better:
Use Cases
When
bar
is genericShould be converted to:
When
bar
isn't genericShould be converted to:
When some parameters are irrelevant
Use
any
Should be converted to:
Examples
x => x
wouldn't returnany
x => [x]
wouldn't returnany[]
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: