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

Inferred function types without generics compile to any #127

Open
jld-adriano opened this issue Apr 26, 2023 · 0 comments
Open

Inferred function types without generics compile to any #127

jld-adriano opened this issue Apr 26, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jld-adriano
Copy link

Bug description

When compiling inferred function types, the output is not as expected

Input

export default function test(input: string) {
  return {
    test: input,
  };
}
export type Test = typeof test;
export type AsType = (input: string) => { test: string };

Expected output

// Generated by ts-to-zod
import { z } from "zod";

export const testSchema = z
  .function()
  .args(z.string())
  .returns(
    z.object({
      test: z.string(),
    })
  );

export const asTypeSchema = z
  .function()
  .args(z.string())
  .returns(
    z.object({
      test: z.string(),
    })
  );

Actual output

// Generated by ts-to-zod
import { z } from "zod";

export const testSchema = z.any();

export const asTypeSchema = z
  .function()
  .args(z.string())
  .returns(
    z.object({
      test: z.string(),
    })
  );

Versions

  • Typescript: v5.0.4
  • Zod: v3.21.3
  • TsToZod: 3.0.0
@tvillaren tvillaren added the enhancement New feature or request label Mar 6, 2024
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