Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to type curried functions #10

Open
Harris-Miller opened this issue Apr 1, 2023 · 3 comments
Open

How to type curried functions #10

Harris-Miller opened this issue Apr 1, 2023 · 3 comments

Comments

@Harris-Miller
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Member

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

DefinitelyTyped/DefinitelyTyped#59579

@Harris-Miller
Copy link
Collaborator Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants