blomqma / next-rest-framework

Type-safe, self-documenting APIs for Next.js
https://next-rest-framework.vercel.app
Other
155 stars 20 forks source link

Zod 3.22.2 incompatible #48

Closed nic-southern closed 1 year ago

nic-southern commented 1 year ago

Having a weird issue with Zod 3.22.2, using the example "todo.ts" I get an error of when doing an "pnpm build"

Type error: Argument of type '{ GET: { output: { status: number; contentType: "application/json"; schema: ZodArray<ZodObject<{ id: ZodString; name: ZodString; completed: ZodBoolean; }, "strip", ZodTypeAny, { ...; }, { ...; }>, "many">; }[]; handler: ({ res }: { ...; }) => void; }; POST: { ...; }; }' is not assignable to parameter of type 'DefineEndpointsParams<BaseSchemaType, AnyZodObject, OutputObject<number, AnyContentTypeWithAutocompleteForMostCommonOnes, BaseSchemaType>, ... 30 more ..., unknown>'. The types of '[ValidMethod.GET].output' are incompatible between these types. Type '{ status: number; contentType: "application/json"; schema: ZodArray<ZodObject<{ id: ZodString; name: ZodString; completed: ZodBoolean; }, "strip", ZodTypeAny, { ...; }, { ...; }>, "many">; }[]' is not assignable to type 'OutputObject<number, AnyContentTypeWithAutocompleteForMostCommonOnes, BaseSchemaType>[]'. Type '{ status: number; contentType: "application/json"; schema: z.ZodArray<z.ZodObject<{ id: z.ZodString; name: z.ZodString; completed: z.ZodBoolean; }, "strip", z.ZodTypeAny, { id: string; name: string; completed: boolean; }, { ...; }>, "many">; }' is not assignable to type 'OutputObject<number, AnyContentTypeWithAutocompleteForMostCommonOnes, BaseSchemaType>'. The types of 'schema.refine(...)._def.typeName' are incompatible between these types. Type 'import("/Users/nic/Git/savsreporting/node_modules/.pnpm/zod@3.22.2/node_modules/zod/lib/types").ZodFirstPartyTypeKind.ZodEffects' is not assignable to type 'Zod.ZodFirstPartyTypeKind.ZodEffects'. Property 'ZodReadonly' is missing in type 'Zod.ZodFirstPartyTypeKind'.

Deploying to vercel causes it to just take forever during the linting stage.

Force installing at the root package level to zod 3.21.4 seemed to resolve the issue. Looks like it is to do with the "readonly" methods introduced in the 3.22 version.

blomqma commented 1 year ago

Hey, can you provide clear instructions to reproduce this, or possibly a public repository/code example where this can be reproduced? The todo example from the readme seemed to work fine for me using zod@3.22.2 and next-rest-framework@0.8.0.

blomqma commented 1 year ago

Closing this due to inactivity, please open another issue if the problem persists.