1
votes

I installed type definition file for Ramda (@types/ramda), when I write the following code, no complains:

const gt5 = (x: number): boolean => x > 5
const inc = (x: number): number => x + 1
const f = pipe(map(inc), filter(gt5))
console.log(f([1,6,8]))

but if I change the order of filter and map:

const gt5 = (x: number): boolean => x > 5
const inc = (x: number): number => x + 1
const f = pipe(filter(gt5), map(inc))
console.log(f([1,6,8]))

I got the following error:

(alias) filter(fn: (value: number) => boolean): R.FilterOnceApplied (+4 overloads) import filter No overload matches this call. The last overload gave the following error. Argument of type 'FilterOnceApplied' is not assignable to parameter of type '(x0: unknown, x1: unknown, x2: unknown) => readonly number[]'. Types of parameters 'source' and 'x0' are incompatible. Type 'unknown' is not assignable to type 'number[] | Dictionary'. Type 'unknown' is not assignable to type 'Dictionary'.ts(2769) index.d.ts(2172, 9): The last overload is declared here.

Of cause the code still runs correctly.

How do I fix this error?

I'm using VSCode.

1
I would suggest asking in the forums of whatever team maintains your typing file. Many of the Ramda experts know little of typescript. - Scott Sauyet

1 Answers

0
votes

filter is supposed to work with both arrays and objects, but typescript gets confused as a result - from here

So one way to fix this error is:

const f = pipe(
  filter<number, "array">(gt5),
  map(inc)
);

Hope it helps!