ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

Fields with `.required()` validation still end up as optional in the type #319

Open jschuur opened 1 year ago

jschuur commented 1 year ago

A field like this

    defineField({
      name: "title",
      type: "string",
      title: "Title",
      validation: (Rule) => Rule.required(),
    })

still ends up with as optional in the type: title?: string;.

Is this to be expected? I see I can add codegen: { required: true }, to the `defineType object, but the that breaks that parameter's types. So now I'm doing this:

    defineField({
      name: "title",
      type: "string",
      title: "Title",
      // @ts-ignore
      codegen: { required: true },
      validation: (Rule) => Rule.required(),
    })
jacksmethurst commented 6 months ago

Having the same issue