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

Class support #268

Open
cAttte opened this issue Sep 17, 2024 · 2 comments
Open

Class support #268

cAttte opened this issue Sep 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@cAttte
Copy link

cAttte commented Sep 17, 2024

Feature description

hey! i was wondering why this wonderful library doesn't have support for classes, the same way that it does for types and interfaces. i felt like this'd be the most interesting use case for ts-to-zod, where you have an existing class that you are using at runtime and simply want to generate a validator for its schema... so i was pretty surprised to not even see a mention of classes anywhere. maybe i'm missing something?

Input

class Dog { barks: boolean }

Output

const dogSchema = z.object({ barks: z.boolean() })
@tvillaren tvillaren added the enhancement New feature or request label Sep 17, 2024
@tvillaren
Copy link
Collaborator

Hey @cAttte

Indeed, class are not supported as I guess nobody (maintainer, contributors or else) have asked for it 😉
This is mostly a community-driven lib, so if you want to take some time to propose a PR, I'll be glad to review it!

@tvillaren
Copy link
Collaborator

Hey @cAttte,

Reading the documentation on zod.dev, I came upon z.instanceof
Would that make sense to use rather than transforming into a z.object?

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

No branches or pull requests

2 participants