sanity-codegen icon indicating copy to clipboard operation
sanity-codegen copied to clipboard

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

Open jschuur opened this issue 2 years ago • 1 comments

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(),
    })

jschuur avatar Jul 31 '23 03:07 jschuur

Having the same issue

jacksmethurst avatar Jan 29 '24 12:01 jacksmethurst