😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Array member type name conflicts with built-in type

This error means you have an array type that has a member that is given the same name as one of the built-in types.

When defining an array type in your schema you have the option to quickly declare several "inline" object types and give each one of them their own name to be able to distinguish between them. For example, the following could be used to define an array that can hold different variations of contact info without having to declare address and phone as separate schema types.

This allows for "locally scoped", inline types that you don't want to re-use across other schema types.

{
  name: 'contactInfo',
  type: 'array',
  of: [
    {
      type: 'object',
name: 'address'
title: 'Address', fields: [{name: 'street', type: 'string'}, /* … */] }, { type: 'object',
name: 'phone'
title: 'Phone', fields: [{name: 'number', type: 'string', /* … */}] } ] }

For inline object types we require their names to not conflict with the built-in types Sanity already ships with.

This means that naming your inline type things like "string", "reference" or "image" will cause an error. Consider this example:

{
  name: 'contactInfo',
  type: 'array',
  of: [
    {
      type: 'object',
      name: 'address'
      fields: [{name: 'street', type: 'string'}, /* … */]
    },
    {
      type: 'object',
name: 'reference' // <-- This will error because "reference" is a built-in type
fields: [{name: 'caption', type: 'string', /* … */}] } ] }

Here, using "reference" as the name for the second object will cause an error because "reference" is the name of a built-in type. The fix here would be to pick another name, e.g. contactReference

The list of built-in types can be found here.

Gotcha

To avoid having multiple similar-typed values with different shapes it might be a good idea to consider "hoisting" inline types to your schema. This will help to make sure every object that share the same _type has the same shape throughout your application.

Was this article helpful?