Skip to content
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

brand() is not supported in z.function().args() #3935

Open
CivilTT opened this issue Jan 5, 2025 · 1 comment
Open

brand() is not supported in z.function().args() #3935

CivilTT opened this issue Jan 5, 2025 · 1 comment

Comments

@CivilTT
Copy link

CivilTT commented Jan 5, 2025

I want to use a branded type in a function's args.

Example:

const Test = z
  .function()
  .args(
    z.string().brand('BrandedString'),
    z.string()
  )
  .returns(z.void());
type Test = z.infer<typeof test>;
// -> (args_0: string, args_1: string, ...args: unknown[]) => void

// But Zod should interpret this type as follows
// -> (args_0: string & z.BRAND<"BrandedString">, args_1: string, ...args: unknown[]) => void

In the following code, I am encountering the error

const Branded = z.string().brand('BrandedString')
type Branded = z.infer<typeof Branded>;

const Test = z
  .function()
  .args(Branded, z.string())
  .returns(z.void());
type Test = z.infer<typeof test>;

const funcs: { sample: Test } = {
  sample: (a: Branded, b: string) => {}
  ^^^^^^
}
// -> Type '(a: Branded, b: string) => void' is not assignable to type '(args_0: string, args_1: string, ...args: unknown[]) => void'.
// -> ...Type 'string' is not assignable to type 'BRAND<"BrandedString">' ts(2322)

I want to be fixed this bug, but if there is a reason for this spec, I would like to know why and what the best practice is.

@anushkasomani
Copy link

I’d like to work on this issue.Can I be assigned to this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants