-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Suggestion: improve DX of type errors from inside pipe
and flow
#3257
Labels
enhancement
New feature or request
Comments
@mikearnaldi I'm curious if you or the team have any thoughts on this? I would be happy to send a PR. |
@OliverJAsh I think that a PR (with all the type tests passing) would be able to push this over the finish line smoothly. Are you still up to champion this? |
OliverJAsh
added a commit
to OliverJAsh/effect
that referenced
this issue
Sep 5, 2024
OliverJAsh
added a commit
to OliverJAsh/effect
that referenced
this issue
Sep 5, 2024
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the problem this feature would solve?
When writing code inside
pipe
andflow
we frequently run into scenarios where a definition is missing e.g. because it hasn't been imported yet. This can result in very confusing error messages due to TypeScript inferringunknown
for the type parameters.Here's a small example comparing the behaviour with and without
pipe
:This is especially problematic inside large pipelines. In my experience it's not uncommon for TypeScript to report multiple errors and highlight hundreds of lines of code just because of one missing import/definition.
What is the feature you are proposing to solve the problem?
This isn't a problem when we're not using
pipe
orflow
:In this case, TypeScript infers the return type of
add
asany
, so there are no further errors.This is the DX we want for
pipe
andflow
: there's just one error and it's clear what and where the error is.How can we mimic this behaviour with
pipe
/flow
? We can use default type parameters:Complete example:
I picked
never
instead ofany
because it felt safer. 🤷♂️What alternatives have you considered?
For arrow functions with an expression body, TypeScript could adjust the position of the return type error so it doesn't cover the entire expression: microsoft/TypeScript#57866.
However, this wouldn't completely fix the problem.
pipe
andflow
would still infer their type parameters asunknown
, resulting in extraneous errors.The text was updated successfully, but these errors were encountered: