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

22 repliesLast updated: Nov 29, 2025

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:

export const myCustomObject = defineType({
  name: 'myCustomObject',
  type: 'object',
  fields: [
    defineField({
      name: 'title',
      type: 'string'
    })
  ]
})
// ❌ This will error
of: [
  {
    type: 'object',
    fields: [...]
  }
]

// ✅ This works
of: [
  {
    name: 'myInlineObject',
    type: 'object',
    fields: [...]
  }
]

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

Was this answer helpful?

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.

Related contributions