Closed Nikola-Milovic closed 1 year ago
Sadly, that would cause another problem:
So, unless we find a solution for that issue as well, I'm afraid I can't merge this PR. Have you tried the schemas in a project? like trpc for example.
Yeah I feared something like this will happen, should've just made this a draft instead. I'll need to explore the project a bit more and see an alternative solution, thanks for trying it out
Problem
When using this library (as an alternative to
zod-prisma
), I want to get thezod schemas
of my databasemodels
and to achieve that I use theCreateInputs
but the issue is that currently we lose some of the abilities of the type inference when we explicitly set the type.Eg
As stated in the docs for generic functions (but it applies here as well) when using
z.ZodType<T>
, this is the toplevel type that all zod types inherit from, meaning we lose the individual functions of the types. For example you cannotextend
ormerge
on anz.object
Suggested solution
If we just drop the explicit
z.ZodType<T>
the typescript will infer it correctly for us and all of the functionality for the specific zod type will be available. NNot sure if this would break something else but it seems redundant to specify the type here instead of letting the TS infer it