omar-dulaimi / prisma-zod-generator

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

Use satisfies instead of type annotation #82

Open mattrossman opened 1 year ago

mattrossman commented 1 year ago

Description

Currently the object schemas look like const Schema: z.ZodType<> = ...;

As mentioned in #64 this causes properties to go missing. However, that PR suggests removing this annotation which @omar-dulaimi states causes problems with tRPC.

This PR uses the satisfies operator to provide the type information instead. I am using this approach in a tRPC project without an issue.

References

Compare the difference in explicit type annotation vs satisfies here:

image

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgLzgXzgMyhEcDkyEAJvgNxxwD0VcMAnmAKYDOAXHAMwB0ATAIzcALACgRTAB6RYdRkzgBVFkygBhKEwCGMeQF5EIysGIcWMKMAB2Ac0NxLmkEwD8p81dtoxAYwiWzispqGtpMAMreABZMIJoAWiQAKnIcyNwJxMnMADxKKupaOgB8cPppEABGAFZM3jAAFAh2xqncZhY29QCUADR2Dk6t7R7d3BBgMMB+mgA23X1oXWJ5wYXhUTHxSXJjIMAwdpRHxycnNHAAes4+fgErBaER0bFh2sAsmMCspShj1bUNJpGEy-YadXr9RxMIbucFjCZTBxzCGLOAsN4fL4sX4ZLJMXJBB7FZaEkI6J6bV6TTGsXb7Q6nRmM85XERAA

mattrossman commented 1 year ago

I added more stuff to my schema and now I get those any errors 🥲 guess it still needs work.

Here is a specific case where it breaks:

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgLzgXzgMyhEcDkyEAJvgNxxwD0VcMAnmAKYDOAXHAMwB0ATAIzcALACgRAOwCGIVmEkBjJnAAKUYCxCTEIykwAekWHUZKAcqxhNiAIQgQANqYCu9+5IBG9pgDFg9y1BwALzalLoAjk6S9iwA-Bzudl6S4nAAPnDiLvY6YeIQMPFw5iyWNknOrh5evv5MgRmJDkwp6ZnZuWgiXSLyEOKlcADK8gAWTJrBKLncEO4AVkzyMAAUCLkRUTEcyNxNyeIrAJSzYDDA-dHH3FlVnkzHADQbmQU7L5TcTuIXhwDau32LUOR0eKG4bmQ9BWx2CAD5ihYrLYHJU3PdagEAPILJYwEbjTRHAC6Rw+cFO50u9mO5Ju2WqD1BnTJn1KamWsJYknOLEwwFY4IAWiQAComAA8qnUmm4JTKKMcDIxfgCcLIYhE+kM8D6A3g8uRFWVNVV9Rxi2WBImWhC1s0GpE9sksxAwHglA+NDgAD1YiIgA

mattrossman commented 1 year ago

Related: https://github.com/colinhacks/zod/issues/2403

omar-dulaimi commented 1 year ago

Hey, thanks for your work on this. Hope we find a solution soon,