ts-to-zod icon indicating copy to clipboard operation
ts-to-zod copied to clipboard

Property shape does not exist on type ZodType

Open cbix opened this issue 1 year ago • 2 comments

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

cbix avatar Mar 16 '23 12:03 cbix

Hi, any update ?

Andy-d-g avatar May 04 '23 13:05 Andy-d-g

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

cbix avatar May 04 '23 13:05 cbix

We're still not supporting zod v3.21.4+?

0xjocke avatar Sep 24 '24 03:09 0xjocke