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

Proposal: use zod's type inference instead of generating full type definitions #317

Open
bagrounds opened this issue Jan 16, 2025 · 0 comments

Comments

@bagrounds
Copy link

bagrounds commented Jan 16, 2025

Proposal:
instead of generating separate type definitions, just export the result of z.infer

Example:

const A = z.string();
type A = z.infer<typeof A>

This would immediately eliminate all discrepancies between the two, ensure no discrepancies ever creep back in, and reduce the maintenance burden of generating valid types that correspond to the zod schemas.

https://zod.dev/?id=type-inference

Originally posted by @bagrounds in #85 (comment)

note: this can be accomplished today with a handlebars template like this:

import { z } from 'zod';

{{#each schemas}}
export const {{@key}} = {{{this}}};
export type {{@key}} = z.infer<typeof {{@key}}>;

{{/each}}
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

1 participant