Skip to content

Shouldn't z.input for templateLiteral be string? #5411

@bamorim

Description

@bamorim

I was trying this today:

const schema = z.templateLiteral(["0x", z.string()]).default("0x")

And I was expecting that alongside z.input I could pass like an env var to it

const value: z.input<typeof schema> = process.env.PRIVATE_KEY

But it doesn't work because the z.input for templateLiteral is the same as the output type.

I'm not sure if this is expected or not, but it was counter-intuitive for me.

(For reference, we use Zod a lot to parse env variables into config objects where we want to at least validate that the "shape" is correct, that is, the keys are correct and that the fields are strings).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions