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

Running into an error when using Method Type Syntax for functions in favour of Function Type syntax #220

Open
FM35 opened this issue Apr 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@FM35
Copy link

FM35 commented Apr 3, 2024

Bug description

export interface HelloWorld {
  sendMsg: (msg: string) => number
}
export interface HelloWorld {
  sendMsg(msg: string): number
}

When I run the yarn ts-to-zod command the first code block suceeds, but the second code block throws the following error:

Screenshot from 2024-04-03 13-09-21

However when I run the ts-to-zod command with the skipValidation flag, the process suceeds.

Input

Specified above

Specified above

Expected output

Should suceed

Not expected any schema for the function. But I believe the method type syntax shoouldn't break the process.

Actual output

Fails to run

// Actual Zod schemas

No output
Versions

  • Typescript: v5.2.3
  • Zod: v3.22.4
@tvillaren
Copy link
Collaborator

Hello @FM35,

Indeed, the generation process works with the --skipValidation flag set but it seems that the generated output does not correspond to the expected one, does it?

In the first case, I get

export const helloWorldSchema = z.object({
  sendMsg: z.function().args(z.string()).returns(z.number()),
});

while in the second case I see

export const helloWorldSchema = z.object({});

I don't see any tests covering the second case, so it seems to me that this syntax is not supported by ts-to-zod for now.

@tvillaren tvillaren added the enhancement New feature or request label Apr 3, 2024
@FM35
Copy link
Author

FM35 commented Apr 3, 2024

Hey @tvillaren , you're right. The output does not correspong to the expected one.

Will that format be supported anytime soon?

@tvillaren
Copy link
Collaborator

It's probably not too hard to add if you want to give it a try 😉

I'm curious, how do you use this in your code?

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