Skip to content

Commit

Permalink
Removed BRAND from ZodBrand Input definition (#1492)
Browse files Browse the repository at this point in the history
* removed brand from input definition

* added tests
  • Loading branch information
Xetera committed Oct 18, 2022
1 parent bc9073d commit 04f28e6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
11 changes: 11 additions & 0 deletions deno/lib/__tests__/branded.test.ts
Expand Up @@ -47,6 +47,17 @@ test("branded types", () => {
true
);

// keeping brands out of input types
const age = z.number().brand<"age">();

type Age = z.infer<typeof age>;
type AgeInput = z.input<typeof age>;

util.assertEqual<AgeInput, Age>(false);

util.assertEqual<number, AgeInput>(true);
util.assertEqual<number & z.BRAND<"age">, Age>(true);

// @ts-expect-error
doStuff({ name: "hello there!" });
});
6 changes: 1 addition & 5 deletions deno/lib/types.ts
Expand Up @@ -3795,11 +3795,7 @@ 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"] & BRAND<B>
> {
> extends ZodType<T["_output"] & BRAND<B>, ZodBrandedDef<T>, T["_input"]> {
_parse(input: ParseInput): ParseReturnType<any> {
const { ctx } = this._processInputParams(input);
const data = ctx.data;
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/branded.test.ts
Expand Up @@ -46,6 +46,17 @@ test("branded types", () => {
true
);

// keeping brands out of input types
const age = z.number().brand<"age">();

type Age = z.infer<typeof age>;
type AgeInput = z.input<typeof age>;

util.assertEqual<AgeInput, Age>(false);

util.assertEqual<number, AgeInput>(true);
util.assertEqual<number & z.BRAND<"age">, Age>(true);

// @ts-expect-error
doStuff({ name: "hello there!" });
});
6 changes: 1 addition & 5 deletions src/types.ts
Expand Up @@ -3795,11 +3795,7 @@ 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"] & BRAND<B>
> {
> extends ZodType<T["_output"] & BRAND<B>, ZodBrandedDef<T>, T["_input"]> {
_parse(input: ParseInput): ParseReturnType<any> {
const { ctx } = this._processInputParams(input);
const data = ctx.data;
Expand Down

0 comments on commit 04f28e6

Please sign in to comment.