Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zod compiles d.ts files with errors #2624

Closed
NickPelov opened this issue Aug 1, 2023 · 3 comments
Closed

Zod compiles d.ts files with errors #2624

NickPelov opened this issue Aug 1, 2023 · 3 comments

Comments

@NickPelov
Copy link

My team recently noticed an issue that came up in the .d.ts files after zod compiled 1 of our schemas.

Original zod schema:

export const UserEventMetadataSchema = EventMetadataSchema.extend({
  userId: z.string().or(z.null()),
  journeyId: z.string(),
  locale: z.string(),
  os: z.string().optional(),
  device: z.string().optional(),
  browser: z.string().optional(),
})

The output in our d.ts file:

export declare const UserEventMetadataSchema: z.ZodObject<z.extendShape<{
    appVersion: z.ZodString;
    environment: z.ZodEnum<["production", "staging", "development"]>;
    clientVersion: z.ZodString;
   ....
},

The problem is that in the d.ts file Typescript cannot find the exported module extendShape:
image

Package versions:

"dependencies": {
    "zod": "^3.21.4",
    "typescript": "^4.9.4"
  },

Does anyone know why the d.ts files are generated with typescript errors?

@mindler-sasu
Copy link

extendShape was moved to another namespace objectUtil.extendShape

@colinhacks
Copy link
Owner

Are you sure your .d.ts files are getting re-generated from your TypeScript source code? Or are these declarations handwritten? This seems to be an issue with having multiple Zod versions conflicting.

@NickPelov
Copy link
Author

At the time we worked around the issue, but I recently noticed this issue was still open and we tried doing a clean install and re-generating our Typescript. The issue seemed to have resolved since the generated code now does not reference the z.extendShape at all.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants