Code-Hex/graphql-codegen-typescript-validation-schema

Satisfies operator

simonljus opened this issue · 1 comments

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>

@simonljus I don't recommend using satisfies operator for now.
Please see #388