zod
                                
                                 zod copied to clipboard
                                
                                    zod copied to clipboard
                            
                            
                            
                        how can I use .extend or .merge with .lazy(() => z.object({ ... }))
as you can see,ZodType does not have extend,so how can I write the type for FormData

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any news?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Wow, closed as stale but this is a real scenario when you have complex lazy objects that might need extending.
I'm playing with ActivityPub and it is extremely nested. Zod seemed like a perfect fit because ActivityPub implementations are all over the place, and I want some sane validation, but the nesting makes things weird.
The crux of the problem here seems to be any object that extends a lazy object must be also lazy, and I'm not sure there's a nice way of enforcing this through zod's syntax.
I ended up exposing the lazy callback as part of the object:
// Object.ts
export type ObjectType = { ... }
export function lazyObjectSchema = () => {
  ...
  return { ... }
}
export const ObjectSchema: z.ZodType<ObjectType> = z.lazy(lazyObjectSchema);
// Document.ts
import { lazyObjectSchema, ObjectType } from "./object.js";
export type Document = ObjectType & {
  ...
};
export const DocumentSchema: z.ZodType<Document> = z.lazy(() =>
  lazyObjectSchema()
    .extend({
      ...
    }),
);
Hope this is helpful to anyone else landing here with nowhere else to go.