-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Index arguments are mandatory, causing problems with typings #1902
Comments
Tacit usage is never advised as it can lead to bugs, in the above code while TS is fine you actually have a bug, given that The right way to use this is: import * as S from "@effect/schema/Schema"
import * as F from "effect/Function"
import * as A from "effect/ReadonlyArray"
const isMyThing = F.pipe(S.string, S.is)
A.takeWhile([false, "this-will-pass"], (a) => isMyThing(a)) Note that generally doing |
I see this issue has been already resolved, but I still just add one thing:
I see this point, and it is fine if you guys have such rule. However, I am not writing code for effect libraries, but writing code for my own things, and I don't see any problems with passing function directly instead of making custom callback for every simple invocation, considering how much verbosity (and thus cognitive overload) it adds to the code. Also, imposing such "bad/good practice" things on users of the library is perhaps a bit off-putting for many developers. |
This is generally not a good idea, not just for So in general, it is advisable to avoid tacit usage of function callbacks across api boundaries. |
Hmm, do you have any reference link to post or something with more information and specifics about this? 🤔 |
While you can decide to do whatever in your code if you are using effect you have to "follow" the effect recommendation when using effect functionality, ergo in this case don't use tacit passing otherwise you end up with bugs. The issue with tacit usage is that for TS you can assign a function with an optional parameter to a function without such parameter, this is effectively an unsound decision made by the TS team, which we have to deal with. also it is valid to pass excess parameters, which means if you combine both that you will get the ability to pass params with invalid types (leading to undefined behaviour). Also TS is weak in checking tacit usage, for example it can't properly discriminate overloads leading to "any" in generics that basically "turn off checking". |
What version of Effect is running?
2.0.3
What steps can reproduce the bug?
Create this kind of code:
What is the expected behavior?
I expect no compilation error.
What do you see instead?
You will get a compilation error
No overload matches this call.
for 2nd argument ofA.takeWhile
.Additional information
This problem stems from the fact that
takeWhile
and a bunch of other functions have mandatory index parameter added to them in #1850. However this conflicts with optionalAST.ParseOptions
accepted by function returned byS.is
.On the other hand, this error makes sense, since
takeWhile
passesnumber
as 2nd parameter, and notAST.ParseOptions
. While making sense technically, the actual real-life usage scenarios of combiningis
and e.g.takeWhile
become cumbersome, as then there is a need to add one extra import and extra explicit typing:Is it possible to change
S.is
to NOT have 2nd optional parameter, and then introduceS.isWithOptions
which does? Or maybeS.isPlain
which does NOT have 2nd optional parameter, and keepS.is
as-is? Or maybe make all indexnumber
parameter fortakeWhile
and friends optional?The text was updated successfully, but these errors were encountered: