Skip to content

Satisfies operator #467

@simonljus

Description

@simonljus

Instead of exporting schemas of a specific type. Let the type be inferred and validated with satisfies.
Would it be possible?

// Example taken from README
export function ExampleInputSchema(): z.ZodSchema<ExampleInput> {
  return z.object({
    email: z.string().min(50).email(),
    message: z.string().regex(/^Hello/, "message")
  })
}

export function ExampleInputSchema() {
  return z.object({
    email: z.string().min(50).email(),
    message: z.string().regex(/^Hello/, "message")
  }) satisfies z.ZodSchema<ExampleInput>
}

// might be easier with const
export const ExampleInputSchema = z.object({
    email: z.string().min(50).email(),
    message: z.string().regex(/^Hello/, "message")} satisfies z.ZodSchema<ExampleInput>

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