Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

I just encountered this error when trying to create an array with two types. Is this not possible, or am I doing something wrong? 😬

1 replies
Last updated: Jan 27, 2021

I just encountered this error when trying to create an array with two types. Is this not possible, or am I doing something wrong? 😬

Jan 27, 2021, 8:34 PM

It's a bit subtle, but

image
 is an actually an object type, and you can't mix primitive types (like numbers and strings) with object types. That means that you have to put your
string
 inside of an object. So:
of: [ { type: 'object', fields: [{type: 'string', name: 'text'}]}, { type: 'image' }]

Jan 27, 2021, 8:36 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.