Skip to content

Predicate created by anyPass can't be used with array .filter #642

@rakeshpai

Description

@rakeshpai

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)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions