-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: strict branding with opt-out #3380
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
B extends string | number | symbol | ||
> extends ZodType<T["_output"] & BRAND<B>, ZodBrandedDef<T>, T["_input"]> { | ||
B extends string | number | symbol, | ||
S extends boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be
S extends boolean | |
S extends boolean = false |
if we don't want breaking changes
@@ -466,8 +466,16 @@ export abstract class ZodType< | |||
}) as any; | |||
} | |||
|
|||
brand<B extends string | number | symbol>(brand?: B): ZodBranded<this, B>; | |||
brand<B extends string | number | symbol>(): ZodBranded<this, B> { | |||
brand<B extends string | number | symbol, S extends boolean = true>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-breaking:
brand<B extends string | number | symbol, S extends boolean = true>( | |
brand<B extends string | number | symbol, S extends boolean = false>( |
): ZodBranded<this, B, S>; | ||
brand< | ||
B extends string | number | symbol, | ||
S extends boolean = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-breaking
S extends boolean = true | |
S extends boolean = false |
when branding, it's useful to retain the branding on
_input
so you have to explicitly pass a branded value when using the schemathis reverts #1492 but with the option of opting out of branded behavior
I can make it a non-breaking change if that's preferred, so it default to non-strict mode
cc @Xetera