chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

Generate types (not just schemas) for Input types? #193

Closed ian-viri closed 8 months ago

ian-viri commented 8 months ago

For 'model' types we get both a generated schema and a generated type. However, for Input types, we only get the schema. This is true even if createInputTypes is true.

For now I'm manually defining them., but am I missing something? Is there a way to have these auto generated?

chrishoermann commented 8 months ago

@ian-viri since the input types are based on prismas generated types, they would just be a copy of the already generated types. So if you need the type of an input schema you can directly import it from prisma client.

ian-viri commented 8 months ago

Interesting. Does that mean the model types can diverge from the Prisma types in some cases?

chrishoermann commented 8 months ago

@ian-viri in a sense they can diverge from the prisma type when you use the writeNullishInModelTypes option.

The model types also do not need a direct type annotation unlike the rekursive input types. This ensures that all the zodMethods like .pick, .omit etc. work on the model types. Many of these methods are not available on the input types due to the type annotation that is needed to provide the correct typing for recursive types.

ian-viri commented 8 months ago

All makes sense -- thanks!