Typescript Errors for flattened error object #2111
Replies: 4 comments 1 reply
-
|
Please send a reproducible code example. |
Beta Was this translation helpful? Give feedback.
-
|
It looks like restarting VS Code has removed these errors so I think we can close this, apologies |
Beta Was this translation helpful? Give feedback.
-
|
It's back.. seems to be when running through the dev server you get these issues. To start the dev server in SvelteKit it's Have attached working directory |
Beta Was this translation helpful? Give feedback.
-
|
I don't know with SvelteKit but here is a snippet of my React Code if it's of any help *✅ safeParse() never throws -> use this for frontend but parse() for backend -> so long as your errors and schema/zod setup is flat (one level deep) I personally think the flattenError stuff is the move! the magic with this is if each field name is tied to zod correctly and your schema is legit (one level deep) then you can typically access the errors with: state.fieldErrors.email[0] etc. I hope this makes sense? Zod changes it's syntax and ecosystem all the time but the flattenedError stuff really helps so long as your data is flat. treeifyErrors or whatever is best if it's really deeply nested. what I tend to do is really break out my zod errors as much as possible. I define my names, my fields, and allll those schemas separately - that way it's far easier to manage them independently and then put them into my form. if you follow that below: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using SvelteKit and it's form actions. When my server.ts file returns a fail, SvelteKit puts the result into the
ActionDataobject, which it assigns for youI'm kicking back Zod validation errors:

Everything actually works, so this could be deemed minor, but Typescript doesn't like the form.errors object

Reading the docs, I see the Extract type signature section, but not being a native TS guy, I'm getting a touch lost with it. Can anyone assist with how to get TS happy?
Beta Was this translation helpful? Give feedback.
All reactions