πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

How to declare a custom type in Sanity.io schema and resolve the issue

11 replies
Last updated: Jul 13, 2023
Hey everybody! Sorry to bother you all but I have an issue I cant figure out, even tho I know the solution is probably simple, and I'd like some guidance if possible:

How do you declare a custom type? For example in the Personal-Website-NextJS template, they have a custom type of "timeline" and "milestone", I want to understand how to do this but I keep getting errors :(
Jul 13, 2023, 1:34 PM
https://www.sanity.io/docs/schemas-and-forms
through the schema you can add custom types if I understand you correctly.
Jul 13, 2023, 1:42 PM
in the first example schema on this page it shows creating a new type called "person"
Jul 13, 2023, 1:42 PM
Just checked your link out. No, that's not what I was looking for.
Let me explain with this:
https://www.sanity.io/docs/schema-field-types (scroll down to the 4th code block)They didn't explain much on how they made the "accessibleImage" type or how they got it to work.
That's where I'm stuck .
Jul 13, 2023, 1:45 PM
they define that in the code block just before it
Jul 13, 2023, 1:46 PM
yes but when I reference it, I get an error that its not an appropriate type
Jul 13, 2023, 1:46 PM
Unknown type: timeline.
Valid types are: settings, array, block, boolean, datetime, date, document, email, file, geopoint, image, number, object, reference, crossDatasetReference, slug, string, telephone, text and url
Jul 13, 2023, 1:47 PM
have you included that type in your schema?
Jul 13, 2023, 1:47 PM
you need to import that type into your schema index file and add it to the array for it to be available
Jul 13, 2023, 1:47 PM
let me try again
Jul 13, 2023, 1:47 PM
ooof, it works now. thank you so much!I guess I was overthinking it. I assumed that 'objects' cant be referenced in the schema index, only 'documents' can. It's appearing and working fine now
πŸ™‚
Jul 13, 2023, 1:54 PM
πŸ™‚ yeah everything you define in the schema needs to be in that schema array, objects and all. glad you got it working πŸ‘
Jul 13, 2023, 1:55 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?