omar-dulaimi / prisma-zod-generator

Prisma 2+ generator to emit Zod schemas from your Prisma schema
MIT License
513 stars 45 forks source link

Do not expliclity type generated schemas #64

Open hco opened 1 year ago

hco commented 1 year ago

Typing them explicitly with ZodType removes some features from the generated schemas.

For example, ZodType lacks features from ZodObject such as .pick, or .merge.

Others have stumbled upon this issue as well, for example, https://github.com/omar-dulaimi/prisma-zod-generator/discussions/24 and https://github.com/omar-dulaimi/prisma-zod-generator/issues/25 bring this up. In https://github.com/omar-dulaimi/prisma-zod-generator/issues/25#issuecomment-1294673830 someone brings up that the change I made broke something in the generator for them. In my case, nothing broke - but this could of course have unwanted side effects. In my understanding, ZodObject extends ZodType, which reduces the risk of issues.

But I am really not sure about this.

omar-dulaimi commented 1 year ago

Indeed, some things got broken. If you try the generated schemas with tRPC, you would face this error(among others):

'PostFindManySchema' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

So, until we found a solution for that problem, we can't really merge this PR sadly