Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

The mapped-type is not recursive in ZodFormattedError (error.format()) #3761

Open
HugoMendes98 opened this issue Sep 18, 2024 · 0 comments · May be fixed by #3762
Open

The mapped-type is not recursive in ZodFormattedError (error.format()) #3761

HugoMendes98 opened this issue Sep 18, 2024 · 0 comments · May be fixed by #3762

Comments

@HugoMendes98
Copy link

Hello, I've noticed that the mapped-type when formatting an error is not reused in the recursive type.
This causes the “sub-levels” _errors of an object to be incorrectly typed.

Here's an example:

declare const error: z.ZodError<{ flat: number; object: { nested: number } }>;

const formatted = error.format(issue => !!issue.fatal);

const ok: boolean[] = formatted._errors ?? [];
// Type 'string[]' is not assignable to type 'boolean[]'
const ko1: boolean[] = formatted.flat?._errors ?? [];
// Type 'string[]' is not assignable to type 'boolean[]'
const ko2: boolean[] = formatted.object?.nested?._errors ?? [];

I solved the problem locally on my end and will probably submit a “PR” soon.

@HugoMendes98 HugoMendes98 changed the title The mapped-type is not recursive in from ZodFormattedError (error.format()) The mapped-type is not recursive in ZodFormattedError (error.format()) Sep 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant