-
Notifications
You must be signed in to change notification settings - Fork 64
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
Generics lost on currying #78
Comments
Thank you for bringing this up. By now, your function will in fact compile, which I hope addresses the original scope of this issue. let updateBy = R.curry(<T>(pred: R.Pred<T>, val: T, array: T[]): T[] => {
let i = R.findIndex(pred, array);
if (i >= 0) {
return R.update(i, val, array);
} else {
return array;
}
});
let res: number[] = updateBy((n: number) => n > 1, 0, [1,2,3]); TypeScript currently feels the result should be |
Once we're able to implement curry the above way, hopefully it could be adjusted to account for placeholders as well (CC @ikatyang). The way I'm imagining this is a three-param function Implementation todo. |
I just added support for In fact, we don't need to wait for variadic kinds. Even with variadic kinds, we would still need recursive types to build analysis types. But it would make the development much easier though. https://github.com/pirix-gh/medium/blob/master/types-curry-ramda/src/index.ts |
@pirix-gh: Thanks! I enjoyed the Medium post (link for others). As you may have noticed, some time has passed since I tried type stuff, meaning a lot of my methods will now seem outdated -- we lacked conditional types / I agree the recursive types issue is pretty important, and I hope they'll acknowledge its importance -- losing recursion would essentially kill any advanced types. Regressions like that were a massive issue for my type repo, particularly as a way to unit test against type non-termination did not exist, meaning things would randomly break on TS upgrades, and it was very hard for me to pin-point which parts broke when and why. I think you've done a great job by getting your types into DT already, as they will do regression tests against this on PRs. A next step up could be to even get some recursive types into the actual TS unit tests, as this could help raise red flags as soon as a TS dev would try something impacting recursion behavior. Then again, just DT may suffice already. Is there any particular meaning to analysis types though? I may have been out of the loop for too long. On another note, I think ahejlsberg's recent PR and @pirix-gh's curry implementation pretty much address the original scope of this particular issue! Let's mark it as fixed. :) |
@tycho01 Thank you! I kind of enjoyed myself writing this :) What I mean by "analysis" types is just types that are "smarter". I like to treat types as if they were functions. As a result, they can be combined together to do input transformation/analysis to output (like we would do in any programming language). And yes, I'm also happy that the types were accepted. It doesn't seem that they use recursive types there at TS, but now there's no regression possible 🗡️. While I was building these recursive types, TS introduced a new error, so I could feel the urge to publish them. These issues arise because TS tries to compute types that receive parameters that haven't been received yet. Like for example: type Concat<T1 extends any[], T2 extends any[]> =
Reverse<Cast<Reverse<T1>, any[]>, T2> Complains that "Type instantiation is excessively deep and possibly infinite". But in fact it just assumed that it's infinite (because of Test00<[any, number], []> // no error
Test00<[...any[]], []> // error, infinite I described a valid workaround for this at the top of the repository... for now. But we won't want this workaround if recursive types become more mainstream, it's kind of ugly and unnecessary. |
@pirix-gh: On the eager depth check, is the workaround that On another note, once Ramda types can be expressed as such analysis types, especially wrapped in a |
Thanks @tycho01 for the tip. It breaks on some of the types though. I am not sure I understand how it works exactly. |
Also see: #73
This (correct) function does not compile
The text was updated successfully, but these errors were encountered: