Create an Array With Two Types - Mixing Primitive Types
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:
Missing the
ofproperty entirely - Arrays require anofproperty 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.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'
})
]
})- Inline objects without a
name- If you're defining an object directly within the array, you must give it aname:
// ❌ This will error
of: [
{
type: 'object',
fields: [...]
}
]
// ✅ This works
of: [
{
name: 'myInlineObject',
type: 'object',
fields: [...]
}
]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.
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.
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.