-
Notifications
You must be signed in to change notification settings - Fork 22
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
Call signature of take
can prevent type inferrence when using curried signature
#69
Comments
The problem you have called out is not isolated to For whatever reason, when you have a return type that is more than a single possibility, generics on those get immediately evaluated. I have a whole write up on it here: #54 The flip side of your fix is you lose support for the overload Here are other alternatives that will solve you problem in the mean time: https://tsplay.dev/m0Voxw |
My solution can still accommodate the string overload, we just have to add another signature for it, so the new declaration would look like this: export function take<T>(n: number, xs: readonly T[]): T[];
export function take<T>(n:number): (xs: readonly T[]) => T[];
export function take(n: number, xs: string): string;
export function take(n:number): (xs: string) => string; |
Okay I actually figured out a workaround that can handle both the string and array curried signature and allow the generic to be evaluated after the original call: https://tsplay.dev/N7QPGW I understand this may not be the ideal solution, it was just an idea I had and thought it was worth mentioning. |
@TClark1011 that's a fantastic solution for the issue with the generic. It won't solve the problem for all the functions that share this issue, but works for |
The current typing of the
take
function is this:Right now, when you call the curried signature inside a pipe, the type of the array is not correctly inferred:
You can see the type inference is working correctly without the `R.take` call:The solution is to change the curried signature for taking from an array to this:
This also applies to
takeLast
.I would be happy to open a PR for this.
The text was updated successfully, but these errors were encountered: