#Error export type for collection

5 messages · Page 1 of 1 (latest)

distant scaffold
#

Hello, I am facing an issue with the code below. I am unable to obtain the export type and I am getting an error specifically related to <typeof test>.

const testSchema = (image: ImageFunction) =>
  z.object({
    title: z.string(),
    src: image().refine((img) => img.width >= 1080, {
      message: "Error",
    }),
  });

export type TestFrontmatter = z.infer<typeof testSchema>;

Error:

Type '(image: ImageFunction) => z.ZodObject<{ title: z.ZodString; src: z.ZodEffects<z.ZodObject<{ src: z.ZodString; width: z.ZodNumber; height: z.ZodNumber; format: z.ZodUnion<[z.ZodLiteral<"png">, z.ZodLiteral<"jpg">, z.ZodLiteral<"jpeg">, z.ZodLiteral<...>, z.ZodLiteral<...>, z.ZodLiteral<...>, z.ZodLiteral<...>]>; }, z...' does not satisfy the constraint 'ZodType<any, any, any>'

Would appreciate any help or solutions that you may have. Thank you.

eager tundra
#

You want the return type of testSchema since it's a function

distant scaffold
#

🙄🤔 Sorry. Can you give an example of the correct method for export? Thank you.

eager tundra
#

z.infer<<ReturnType<typeof testSchema>> should do the trick, I think

#

I'm on mobile so syntax might not be exact