-
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
Higher order functions lose type parameters #417
Comments
👍 |
Gonna go with dupe of #360. |
Marking this as a duplicate of #360 seems to imply to me that we're going down this route:
Please correct me if I'm wrong with that assumption. As stated previously:
Is this feasible? Is the problem here that |
Actually, the issue is that we instantiate all type parameters at call-site - they are not curried. While not a duplicate per se, what you are seeing (lack of available candidates to instantiate Edit: I previously answered "yes" to your question - I misunderstood and have amended my comment. |
Basically what I meant was that if we can make generics better at representing certain type patterns we'll certainly do that but our current design is what it is for good reasons (some of which Daniel just described) and we're generally aware of a number of shortcomings that result from the current design. Given that, #360 captures what's the most likely near term result here. I didn't want to leave this open and say 'feel free to propose a new algorithm for generic type inference' since that's not exactly a small task and we've certainly spent a lot of time on it ourselves and ended up with this design. That said, if you do have or end up having a proposed design for how to fix generics in this respect feel free to log a new issue with the details :) |
I don't underestimate the work put in to solving this problem, I was just trying to better understand it. If I have a moment of divine inspiration, I'll be sure to file said issue :-] |
flowtype actually capture types, would it not be possible to inspire from their algorithm ? |
Tracked by #9366 |
Fixed in #30215. |
When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how
identityM
has the generic type parameterA
changed into{}
, resulting in a loss of type safety in the rest of the code.Ideally
identityM
would have the type<A>(a: A) => A
. If this isn't possible, issuing a compiler warning (or error) about loss of genericity would be very helpful in tracking down errors like this.The text was updated successfully, but these errors were encountered: