Converting Zod to Arktype
Hello!
I'm really interested in using Conform instead of React Hook Form for better DX and server-side capabilities. However, it doesn't have Ark support yet, so I'll have to create my own simple patch.
Are there by any chance some examples or comparisons between Zod and Arktype architectures to go off of when translating these files, namely to extract the name of the constraints like
Array
in runtime?
expression
might be "key"? pun intended
https://github.com/edmundhung/conform/blob/main/packages/conform-zod/constraint.ts
https://github.com/edmundhung/conform/blob/main/packages/conform-zod/parse.ts
Also, is there an way to do something like superRefine
for custom run-time conditions?
https://zod.dev/?id=superrefine87 Replies
Sorry I missed this. It looks like you've figured out some of this.
You can iterate over the errors and check
.code
to check the kind of error it was. It has lots of additional introspectable information about the type of error.
superRefine
is just a long-winded narrow
😅Ah, thank you! I'm slowly starting to understand morphs and constraints
I've been looking through the tests, and got a bunch of questions answered
The possiibilities are endless 🤯
I appreciate your diligence! Unit tests definitely the best place to see comprehensive docs at the moment haha
Yes, I in turn appreciate your thoroughness in writing the tests, it's really helpful
It's also helpful for making sure everything works 😅
But I couldn't find an example on how to create/edit types on runtime 🥹
This seemed to get me far enough, but then when I acually use it, it thinks all the values are missing
If there is a specific test or discussion about it, I'd gladly read it, I just couldn't find the proper keywords to find it
This kind of internal type mapping stuff isn't really a big focus of the documentation yet. It mirrors a lot of operations in TS, but there's a ton of nuance to the way unions, structures etc. are handled (like in TS)
Here's a cleaner implementation though:
It will be nice when there is a mapped type abstraction built around this
Maybe I will add it now
So the first callback if for iterating the keys, and the second callback is for building the result object, which
distribute
returns?Yeah
Got ittttt.......
It works ;-;-;-;-;-;
That makes me so happy
I bashed my head on the wall for about 4 hours with this yesterday 😆
Haha yeah it helps to know how the type system works
Do you know why this acted like it did?
Your biggest problem is that you were treating
key
like a literal key but it was a node
So I guess it gets converted to a string using .expression
And the actual literal is
key.unit
Yeah