ramda / types

MIT License
26 stars 21 forks source link

How to type curried functions #10

Open Harris-Miller opened 1 year ago

Harris-Miller commented 1 year ago

ramda's curry function is awesome but also has abilities that are not strictly necessary to type

// all of these work!
R.divide(10, 2); // 5
R.divide()(10, 2); // 5
R.divide(R.__)(10, 2); // 5

The use cases for both R.divide() and R.divide(R.__) are however negligible

So when typing out, we're only going to type it as:

export function divide(a: number, b: number): number;
export function divide(__: Placeholder, b: number): (a: number) => number;
export function divide(a: number): (b: number) => number;

And leave out

export function divide(): (a: number, b: number) => number;
export function divide(__: Placeholder): (a: number, b: number) => number;
Harris-Miller commented 1 year ago

It is also worth noting that there are many places in @types/ramda where there are typing for R.fn(__) that is incorrect. See lt for example

They have there

export function lt(__: Placeholder): (b: number, a: number) => boolean;

This implies that lt(__) is the same as flip(lt), which is incorrect. Therefore, those type definitions will be removes as part of types-ramda overall typing improvements

adispring commented 1 year ago

Or should we forbid using placeholder when use ramda with ts?

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59579

Harris-Miller commented 1 year ago

@adispring I read through that PR along with the links to the other discussions from there.

I don't have a particularly strong opinion on the keep/no-keep argument. However, the fact of the matter is that placeholders are supported, and therefore need to be typed out

The argument I made above was specifically for the use cases that don't really make sense to keep

R.divide === R.divide() === R.divide(R.__);

But I'm willing to bet that somewhere someone has implemented

const toPercent = R.divide(R.__, 100);

So removing Placeholder support would break their code. Need to keep