Closed mmkal closed 2 weeks ago
isZodErrorLike
does exist already (but doesn’t seem documented).
Correct, it exists already but it's not documented. Let us fix this.
@mmkal have a look at this PR (https://github.com/causaly/zod-validation-error/pull/378)
Great! Thanks
Hi! This library is great, but there's a helper I find myself needing to write myself for it when I use it - a check to see if an error is a zod error in the first place. This will help with code like this where we don't actually know if an error is a zod error or something else:
For the same reasons that using
instanceof
is a bad idea on ValidationError, it's even worse on ZodError because there are so many dependencies on zod, it's quite likely that you'll end up with the wrong one.I've used this in trpc-cli:
That covers inheritance too, which it looks like
isValidationErrorLike
doesn't right now: https://github.com/causaly/zod-validation-error/blob/60b423086edb78b7d7678317196906fbbe6221da/lib/isValidationErrorLike.ts#L3-L5