Predicate created by `anyPass` can't be used with array `.filter`
rakeshpai opened this issue · 4 comments
rakeshpai commented
The following example gives a compile error:
import { anyPass, filter } from "rambda";
const isGt5 = (num: number) => num > 5;
const pred = anyPass([isGt5]);
const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const filtered1 = filter(pred)(xs); // works
const filtered2 = xs.filter(pred); // compile error
This is the compile error:
No overload matches this call.
Overload 1 of 2, '(predicate: (value: number, index: number, array: number[]) => value is number, thisArg?: any): number[]', gave the following error.
Argument of type 'SafePred<number>' is not assignable to parameter of type '(value: number, index: number, array: number[]) => value is number'.
You can see this example in action here: https://codesandbox.io/s/pedantic-jennings-ret7c2?file=/src/index.ts
I think this is because of the type definition of SafePred
, which is incompatible with the definition of the function taken in by array .filter
. I'm not sure why SafePred
is defined this way, with (...x: T[])
as the arguments. Shouldn't it be just (x: T)
?
selfrefactor commented
I will look into it. Thank you for the detailed report; that makes things easier.
selfrefactor commented
It is fixed and will be released with 7.2.0
rakeshpai commented
Thanks a ton, @selfrefactor!
selfrefactor commented
Closing the issue as fix was released with 7.2.0