fp-ts icon indicating copy to clipboard operation
fp-ts copied to clipboard

Incorrect ReadonlyArray.difference Override Referenced with flip

Open JLambertazzo opened this issue 2 years ago • 2 comments

🐛 Bug report

Current Behavior

using flip from fp-ts/lib/function and ReadonlyArray.difference from fp-ts/ReadonlyArray

Applying flip to ReadonlyArray.difference uses the non-curried override of the difference method rather than the curried override. This results in the use of a deprecated flip override being used to to flip a non-curried method, and the resulting flipped function does not work as expected.

Below is on a fresh project after installing typescript and fp-ts: Screen Shot 2022-10-31 at 9 08 06 PM

Expected behavior

The flip function should use the curried version of ReadonlyArray.difference by using the non-deprecated version of flip.

Below is same code as above but using a custom curried difference function: Screen Shot 2022-10-31 at 9 12 34 PM

Reproducible example

See screenshots above

Suggested solution(s)

It seems weird to me that the deprecated override of a function is being used when the non-deprecated override can be used. Maybe there's a way to use the deprecated one only if the the non-deprecated override can't be applied?

Additional context

Your environment

Which versions of fp-ts are affected by this issue? Did this work in previous versions of fp-ts?

Using [email protected]. Haven't tried with previous versions

Software Version(s)
fp-ts 2.13.1
TypeScript 4.8.4

JLambertazzo avatar Nov 01 '22 01:11 JLambertazzo

Maybe there's a way to use the deprecated one only if the the non-deprecated override can't be applied?

I'm not sure we can impose which override ts will choose in this specific case

gcanti avatar Nov 01 '22 08:11 gcanti

Seems the preference comes from the order of signatures in the .d.ts file for ReadonlyArray. Tested with: Problem described above

Current order of function signatures in fp-ts

Proposed order of function signatures (deprecated first)

Result, non-deprecated function signature being used first

JLambertazzo avatar Jan 25 '23 01:01 JLambertazzo