Sanity Library Reference Docs
    Preparing search index...

    Function defineField

    • Beta

      Define a field within a document, object, image or file definition fields array.

      This function will narrow the schema type down to fields and options based on the provided type-string.

      Using defineField is optional, but should provide improved autocompletion in your IDE, when building your schema. Field-properties like validation and initialValuewill also be more specific.

      See defineType for more examples.

      Type Parameters

      • const TType extends
            | "string"
            | "number"
            | "boolean"
            | "object"
            | "text"
            | "crossDatasetReference"
            | "reference"
            | "image"
            | "document"
            | "url"
            | "email"
            | "date"
            | "block"
            | "array"
            | "datetime"
            | "file"
            | "geopoint"
            | "globalDocumentReference"
            | "slug"
            | "sanity.video"
            | AutocompleteString
      • const TName extends string
      • TSelect extends Record<string, string>
      • TPrepareValue extends Record<keyof TSelect, any>
      • TAlias extends
            | "string"
            | "number"
            | "boolean"
            | "object"
            | "text"
            | "crossDatasetReference"
            | "reference"
            | "image"
            | "document"
            | "url"
            | "email"
            | "date"
            | "block"
            | "array"
            | "datetime"
            | "file"
            | "geopoint"
            | "globalDocumentReference"
            | "slug"
            | "sanity.video"
      • TStrict extends StrictDefinition

      Parameters

      Returns { name: TName; type: TType } & DefineSchemaBase<TType, TAlias> & NarrowPreview<
          TType,
          TAlias,
          TSelect,
          TPrepareValue,
      > & MaybeAllowUnknownProps<TStrict> & FieldDefinitionBase & WidenValidation & WidenInitialValue

      • defineField
      • defineArrayMember
      • typed