colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.61k stars 1.16k forks source link

ZodObject.extends() metadata #2310

Open samchungy opened 1 year ago

samchungy commented 1 year ago

It would be very useful to have some information stored against the ZodObject about the object which was extended from.

Context: I'm trying to create a plugin which will be enhanced by knowing when an object extended another.

eg.

const a = z.object({
  prop1: z.string()
});

const b = a.extend({
  prop2: z.string()
});

console.log(b._def.extends)
// returns reference to a
j-murata commented 1 year ago

@samchungy FYI: #2206

samchungy commented 1 year ago

@samchungy FYI: #2206

Haha touche https://github.com/samchungy/zod-openapi/blob/13e8c9236821b7e559ad724d9b3b6d33ca2893d4/src/extendZod.ts#L98. Still would be nice to be native