Help articles

Array type is missing or has an invalid value for the "of" property

Sanity Studio reports The array type is missing or having an invalid value for the required "of" property when an array type has no of, or when of is not an array.

All array types must define what kind of items they may contain. The of property must be an array of objects that describes the type of a valid item. Each entry in of must have a type property which must be the name of a valid schema type.

import {defineArrayMember, defineField} from 'sanity'

export const items = defineField({
  type: 'array',
  name: 'items',
  // The "of" property must be set, and it must be an array
  of: [
    defineArrayMember({type: 'author'}), // type is required
    defineArrayMember({type: 'book'}),
  ],
})

Types must be unique, or named

Sanity Studio reports Found 2 members with same type, but not unique names "author" in array. This makes it impossible to tell their values apart and you should consider naming them when two members share a type and neither is named.

In order to know which type description an array item belongs to, you can't add multiple entries to of with the same type unless you give them distinct name values to tell them apart. This is therefore not allowed:

import {defineArrayMember, defineField} from 'sanity'

export const items = defineField({
  type: 'array',
  name: 'items',
  of: [
    defineArrayMember({type: 'author'}),
    // 💥 ERROR: no way to tell the two members apart
    defineArrayMember({type: 'author'}),
  ],
})

Instead, you can give items of the same type another name. This will work:

import {defineArrayMember, defineField} from 'sanity'

export const items = defineField({
  type: 'array',
  name: 'items',
  of: [
    defineArrayMember({type: 'author', title: 'Author'}),
    defineArrayMember({type: 'author', name: 'anotherAuthor', title: 'Another author'}),
  ],
})

Items in this array will have their _type set to either author or anotherAuthor, depending on which of the types was selected when the item was added. For example:

[
  {"_type": "author", "name": "Camilla Collett"},
  {"_type": "anotherAuthor", "name": "Henrik Ibsen"}
]

Other causes

Two further cases report the same error. An array with a block member alongside an object member that has no name reports The array type's 'of' property can't have an object type without a 'name' property as member, when the 'block' type is also a member of that array. An array that mixes object types and primitive types reports The array type's 'of' property can't have both object types and primitive types, followed by the offending type names.

Was this page helpful?