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

Property shape does not exist on type ZodType #123

Open
cbix opened this issue Mar 16, 2023 · 2 comments
Open

Property shape does not exist on type ZodType #123

cbix opened this issue Mar 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@cbix
Copy link

cbix commented Mar 16, 2023

Bug description

ts-to-zod v3.0.0 generates a Zod schema that fails type verification with this error:

2339: Property 'shape' does not exist on type 'ZodType<test, ZodTypeDef, test>'.

Looking into the ZodType (exported as ZodSchema) definition it in fact doesn't have any field called shape.

Input

The input file is generated by openapi-typescript v6.2.0 but I could reproduce the issue with a type definition as simple as this:

// typescript type or interface causing the output
export interface test {
  schemas: {
    A: string | null;
    B: test['schemas']['A'][];
  };
}

Expected output

Not exactly sure ...

Actual output

// Actual Zod schemas
// Generated by ts-to-zod
import { z } from 'zod';
import { test } from './test.d';

export const testSchema: z.ZodSchema<test> = z.lazy(() =>
  z.object({
    schemas: z.object({
      A: z.string().nullable(),
      B: z.array(testSchema.shape.schemas.shape.A),
    }),
  }),
);

Versions

  • Typescript: v4.9.5
  • Zod: v3.21.4
@Andy-d-g
Copy link

Andy-d-g commented May 4, 2023

Hi, any update ?

@cbix
Copy link
Author

cbix commented May 4, 2023

Btw, this issue is not relevant to me anymore since we switched from openapi-typescript + ts-to-zod to openapi-zod-client.

@tvillaren tvillaren added the bug Something isn't working label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants