Cannot create array with two types - error or wrong syntax?

22 replies
Last updated: Jan 28, 2026
I just encountered this error when trying to create an array with two types. Is this not possible, or am I doing something wrong? 😬
AI Update

Arrays with multiple types are absolutely possible in Sanity - in fact, they're one of its core features! Without seeing your specific error message, here are the most common issues people run into:

The correct way to define arrays with multiple types:

defineField({
  name: 'myArray',
  type: 'array',
  of: [
    {type: 'block'},  // Standard rich text
    {type: 'image'},  // Built-in image type
    {type: 'myCustomObject'},  // Your custom object
  ]
})

Common problems that cause errors:

  1. Missing the of property entirely - Arrays require an of property that defines what types can be included. If you're seeing an error about an invalid or missing "of" property, make sure you have this structure.

  2. Missing type definitions - If you reference a custom type like {type: 'myCustomObject'}, that type must be defined somewhere in your schema:

export const myCustomObject = defineType({
  name: 'myCustomObject',
  type: 'object',
  fields: [
    defineField({
      name: 'title',
      type: 'string'
    })
  ]
})
  1. Inline objects without a name - If you're defining an object directly within the array, you must give it a name:
// ❌ This will error
of: [
  {
    type: 'object',
    fields: [...]
  }
]

// ✅ This works
of: [
  {
    name: 'myInlineObject',
    type: 'object',
    fields: [...]
  }
]
  1. Type name conflicts - Make sure your array member type names don't conflict with built-in types or other global type names in your schema.

  2. Schema not imported - Ensure your custom types are imported and included in your main schema configuration file.

You can also use the defineArrayMember helper for better TypeScript support:

of: [
  defineArrayMember({type: 'block'}),
  defineArrayMember({type: 'image'}),
  defineArrayMember({
    name: 'customBlock',
    type: 'object',
    fields: [...]
  })
]

If you share the specific error message you're seeing, I can give you more targeted help! Common errors include "invalid 'of' property" or "unknown type" messages.

Show original thread
22 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?