Skip to content

Add Generic Type Argument to the produced schema #347

@Sebastian-Nielsen

Description

@Sebastian-Nielsen

Feature description

Add the interface to the resulting schema (the <Example> part):

export const ExampleSchema = z.object<Example>({
  id: z.string(),
  name: z.number(),
});

// or alternatively generate with `satisfies z.ZodType<Example>`

export const ExampleSchema = z.object({
  id: z.string(),
  name: z.number(),
}) satisfies z.Zodtype<Example>;

This way, if the programmer changes the Example interface, the interface and schema is now out of sync and they get a type-error as a reminder to re-sync.

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