-
-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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>( | ||||||
brand?: B, | ||||||
opts?: { | ||||||
strict: S; | ||||||
} | ||||||
): 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 commentThe reason will be displayed to describe this comment to others. Learn more. non-breaking
Suggested change
|
||||||
>(): ZodBranded<this, B, S> { | ||||||
return new ZodBranded({ | ||||||
typeName: ZodFirstPartyTypeKind.ZodBranded, | ||||||
type: this, | ||||||
|
@@ -2357,9 +2365,10 @@ export class ZodObject< | |||||
const syncPairs: any[] = []; | ||||||
for (const pair of pairs) { | ||||||
const key = await pair.key; | ||||||
const value = await pair.value; | ||||||
syncPairs.push({ | ||||||
key, | ||||||
value: await pair.value, | ||||||
value, | ||||||
alwaysSet: pair.alwaysSet, | ||||||
}); | ||||||
} | ||||||
|
@@ -4726,8 +4735,13 @@ export type BRAND<T extends string | number | symbol> = { | |||||
|
||||||
export class ZodBranded< | ||||||
T extends ZodTypeAny, | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. this could be
Suggested change
if we don't want breaking changes |
||||||
> extends ZodType< | ||||||
T["_output"] & BRAND<B>, | ||||||
ZodBrandedDef<T>, | ||||||
S extends true ? T["_input"] & BRAND<B> : T["_input"] | ||||||
> { | ||||||
_parse(input: ParseInput): ParseReturnType<any> { | ||||||
const { ctx } = this._processInputParams(input); | ||||||
const data = ctx.data; | ||||||
|
@@ -4999,7 +5013,7 @@ export type ZodFirstPartySchemaTypes = | |||||
| ZodDefault<any> | ||||||
| ZodCatch<any> | ||||||
| ZodPromise<any> | ||||||
| ZodBranded<any, any> | ||||||
| ZodBranded<any, any, any> | ||||||
| ZodPipeline<any, any> | ||||||
| ZodReadonly<any> | ||||||
| ZodSymbol; | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: