Removal of Placeholder
/ __
support for curried functions
#51
Harris-Miller
started this conversation in
Polls
Replies: 2 comments
-
Yes there have definitely been discussions about removing the placeholder. I could go either way there, but whatever ramda decides, I think it is fair for it to be removed from types-ramda |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here's the discussion about removing placeholder‘s type before: DefinitelyTyped/DefinitelyTyped#59579 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The Problem
Over the last 6 months of revamping the type definitions for
ramda
, the support forPlaceholder
/__
has been one of the single most challenging partsThere are 3 things in particular that have been of major hindrance
Placeholder
satisfies the argument typeSupport for 3+ arity function
This is the most obvious. Just look at the type definition for this PR. Supporting these are just difficult. They also make the intellisense extremely confusing
Using the PR for
assoc
above as an example, there are 7 overloads with support forPlaceholder
, and only 3 if I were to remove themSupport when
Placeholder
satisfies the argument typeThis one is less obvious but quite annoying.
Placeholder
can satisfy the argument type sometimes, particularlyPropertyKey
which is used a lot. Alsoany
This means that you have to disclude
Placeholder
in some types of definitions and it gets very messyI'm not actually sure how many places the above example is true for with the current type definitions we have, but I'm willing to be it is a lot. It's not great to have
Type error feedback
This one is also less obvious, but very annoying. When you have a function that includes an overload with a Placeholder, if you call that function and get a type error, the error that gets displayed is for the first overload, even if the one you were trying to use was the second.
This is because the
Placeholder
overload needs to come firstThe error you see for this situation displays as
It is difficult to make out what is going on because you are getting an error display for both overloads, and the
Placeholder
one comes first. This can be especially challenging for less experienced Typescript developersIf I were to remove the
Placeholder
overload you would get this insteadThe error here is very clear and to the point
The Solution
Removing typescript support for
Placeholder/
__` overloads for all curried types I think will be beneficial in the long run for ramda's typings.First, so it is very clear, I have no intention of removing curried types, just those with the
Placeholder
typeWill become
This will, for the most part, remove 2 general use-cases, however both can be remedied with the use of arrow functions
The first use-case being creating stand-alone functions from ramda functions
The major drawback for this is you will have to type
x
yourself thereThe second is usage in
pipe
/compose
Unlike the stand-alone-function example, you get the type of
x
for free, becausepipe
knows thatadd()
returns anumber
, sox
must be a numberIMHO this is a small and acceptable concession to make in how we use ramda with typescript to better overall support ramda with typescript.
Additionally, although I cannot seem to find these discussions over at
ramda/ramda
, I know they exist... There has been an argument for removing support forPlaceholder/
__` in the javascript code itself as well. I believe @adispring can speak to that.The poll I have created is a simple Yes/No response. Please leave a comment if you disagree with this assessment or have an alternative solution.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions