zod-to-json-schema icon indicating copy to clipboard operation
zod-to-json-schema copied to clipboard

Would it be possible to retain branded types?

Open ConnorSinnott opened this issue 10 months ago • 1 comments

Howdy! I understand that the branding system doesn't really exist at runtime, but there could be value in adding wrappers which enable the JSON ser/de to retain the brands. Something along the line of zodToJsonSchemaBranded('my-brand', z.___.brand()) where zodToJsonSchemaBranded<T extends string>(brand: T, schema: z.ZodBranded<T>). I think it could be possible for inner .brand function to infer the string from the wrapper.

ConnorSinnott avatar Apr 17 '24 00:04 ConnorSinnott

Hi! Thanks for opening an issue. I'm hesitant to expanding the API for this. Perhaps use the override feature?

StefanTerdell avatar Apr 23 '24 03:04 StefanTerdell

Closing for now! Feel free to reopen if it doesn't work out.

StefanTerdell avatar May 06 '24 17:05 StefanTerdell

No problem! Thanks for the support!

ConnorSinnott avatar May 06 '24 19:05 ConnorSinnott