Schema type is missing a required property
Every schema type needs both a type and a name property. Studio reports one of these problems when either is missing or has the wrong shape:
Missing type name— the type has nonameproperty.Type is missing a type.— the type has notypeproperty.Type has an invalid "type"-property - should be a string.— thetypeproperty is set to something that isn't a string.
The type property says which type your schema type builds on — for example a document, an object, or a string. The name is what you use to refer to this type elsewhere in your schema. To add a field that references one of your own types, you refer to it by name:
import {defineType, defineField} from 'sanity'
const author = defineType({
name: 'author', // the name other types use to refer to this type
type: 'document',
fields: [defineField({name: 'name', type: 'string'})],
})
const book = defineType({
name: 'book',
type: 'document',
fields: [
defineField({name: 'title', type: 'string'}),
defineField({
name: 'author',
type: 'reference',
to: [{type: 'author'}], // refers to the "author" type by its name
}),
],
})
export const schemaTypes = [author, book]Studio's schema errors screen names the type each problem belongs to, so start there. Declaring your types with defineType and defineField catches all three problems in your editor, before Studio starts.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?