Post

I love this pattern. I'd go further than - not to be an defender of abstraction which is so uncool now - but in medium to large projects, you should usually do something like this for any dependencies that you use in more than a handful of places.

an underutilized pattern to add custom functionality to Zod: create a "my-zod.ts" file that re-exports everything from zod. then define additional types/functionality in that file. then you can do `import * as z from "./myzod"` to use your custom types alongside Zod's built-ins

It makes it so much easier to - add functionality - upgrade to new major versions - narrow types to your domain - switch to another dependency entirely - apply patches/side effects without them "infecting" the rest of your codebase

0 reposts2 likes

No replies yet.