We need your help to implement the pipe
function 🙏
#498
Replies: 5 comments 13 replies
-
I took a quick look, and if I'm understanding the API correctly, the first issue can be resolved by ensuring the input type is correctly treated as contravariant so a broader type like However, you will run into a limitation inferring piped output with this approach. Without using HKTs, you will not be able to have a function like The options for working around this are to define your actions as HKTs like those in HotScript or hkt-toolbelt so they can be applied at a type-level and return a result that depends on the input, or to use a different API. ArkType's next release uses chaining to handle this scenario: Hopefully something like that could be made compatible with your tree-shaking strategy? |
Beta Was this translation helpful? Give feedback.
-
Does this work the way you intend? Seems like the types flow pretty good but could just be accidental |
Beta Was this translation helpful? Give feedback.
-
Does this work?
Let me know if I'm missing any edge case? 🤔 |
Beta Was this translation helpful? Give feedback.
-
I've heard that it's not possible to implement the pipe function in TypeScript "normally" like in other languages. That's why the pipe function in RxJS was written like that https://github.com/ReactiveX/rxjs/blob/master/packages/rxjs/src/internal/util/pipe.ts |
Beta Was this translation helpful? Give feedback.
-
Feel free to take a look at the draft PR for the |
Beta Was this translation helpful? Give feedback.
-
Based on #463 I started to rewrite Valibot and implement the
pipe
function. The results so far are promising. I was able to reduce the bundle size, improve type safety and fix some general issues. Unfortunately, I hit a TypeScript limitation or bug. My current implementation is completely typesafe. Even the issues are now fully typed. So I want to avoid compromising here at all costs.Is there a TypeScript wizard in our community like @mattpocock or @ssalbdivad that can find a workaround? I have created a TypeScript playground with a minimal reproduction.
Beta Was this translation helpful? Give feedback.
All reactions