Invalid shape of predefined choices
This error means an entry in an array's options.list isn't a valid value for the array's declared member types.
As a general rule, the list of possible choices for array types must only contain values of valid item types for the array.
The exact message depends on what the array holds. For an array of objects it ends with Must be an object with "_type" set to …. For an array of primitives it ends with Must be either a value of type …, or an object with {title: string, value: …}.
import {defineArrayMember, defineField, defineType} from 'sanity'
export const colors = defineType({
name: 'colors',
type: 'array',
of: [
defineArrayMember({
type: 'object',
name: 'webColor',
fields: [
defineField({name: 'name', type: 'string'}),
defineField({name: 'hex', type: 'string'}),
],
}),
defineArrayMember({
type: 'object',
name: 'rgbaColor',
fields: [
defineField({name: 'name', type: 'string'}),
defineField({name: 'r', type: 'number'}),
defineField({name: 'g', type: 'number'}),
defineField({name: 'b', type: 'number'}),
defineField({name: 'a', type: 'number'}),
],
}),
],
options: {
list: [
// Valid
{_type: 'webColor', hex: '438D80', name: 'Sea Turtle Green'},
// Valid
{_type: 'rgbaColor', r: 161, g: 201, b: 53, name: 'Salad Green'},
// Invalid: an object entry is matched on its _type, and a
// {title, value} wrapper doesn't have one
{
title: 'Sea Turtle Green',
value: {_type: 'webColor', hex: 'C88141', name: 'Tiger Orange'},
},
// Invalid: missing _type
{hex: '438D80', name: 'Sea Turtle Green'},
// Invalid: hslaColor is not one of this array's member types
{_type: 'hslaColor', h: 0.02, s: 0.93, l: 0.71, name: 'Salmon'},
],
},
})A notable exception here is choices for primitive values, which can be given a display title by providing an object with title and value, where value is of a valid item type:
import {defineArrayMember, defineType} from 'sanity'
export const numbersAndAnimals = defineType({
name: 'numbersAndAnimals',
type: 'array',
of: [
defineArrayMember({type: 'string'}),
defineArrayMember({type: 'number'}),
],
options: {
list: [
// Valid: this array can contain strings
'sheep',
// Valid: this array can contain numbers
44,
// Valid: a primitive value can be given a display title
{title: 'Cat', value: 'cat'},
// Valid: the same works for numbers
{title: 'Hundred', value: 100},
// Invalid: this array can't contain booleans
true,
],
},
})