Closed danielbayley80 closed 1 year ago
It's problematic to use schemas between modules because it will be a prototype mismatch, so instanceof
checks will fail, and there are a couple of those in Superforms. Zod has a way of handling this, but I'm not sure if I can squeeze that in before 1.0.
Understood. I like to use lots of modules to allow reuse of key code across projects. I have a workaround creating the z.object() in the svelte page which only adds a line of code and a bit of tweaking to my modules. Otherwise I'm really enjoying working with the library so far.
Fortunately it wasn't that much work to fix, so it will be no problem to use it cross-module schemas for 1.0! Just a few days from release.
Is it working now with 1.0?
Closing this, as all the tests are passing.
When I define my Zod in another module (which I do to enable reuse across projects), I get:
"SuperFormError: Only Zod schema objects can be used with superValidate."
The same object when defined in the SvelteKit project works.
Or if I create my zod object in my module as follows :
then do this in svelete:
const cmsSiteVal = z.object(cmsSiteZod);
it recognizes it.
vscode seems to recognize the types correctly.
I should add I had trouble getting my modules working in SveleteKit vs my express projects, but I think I cracked it and it works in other areas.