How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

How to declare custom types in Sanity schema?

11 repliesLast updated: Nov 29, 2025

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 :(
AI Update

No worries, this is a common question when starting with Sanity! Creating custom types is actually straightforward once you understand the pattern.

In Sanity, you define custom types in your schema files using the defineType helper function. For the Personal Website template's "timeline" and "milestone" types, here's how it works:

Basic structure for a custom document type:

import { defineType, defineField } from 'sanity'

export const timeline = defineType({
  name: 'timeline',
  type: 'document',
  title: 'Timeline',
  fields: [
    defineField({
      name: 'title',
      type: 'string',
      title: 'Title',
    }),
    // more fields...
  ],
})

For a custom object type (like milestone):

export const milestone = defineType({
  name: 'milestone',
  type: 'object',  // Note: 'object' not 'document'
  title: 'Milestone',
  fields: [
    defineField({
      name: 'description',
      type: 'string',
      title: 'Description',
    }),
    // more fields...
  ],
})

Key differences:

Then register them in your schema:

In your sanity.config.ts (or schema/index.ts):

import { timeline } from './schemas/timeline'
import { milestone } from './schemas/milestone'

export default defineConfig({
  // ... other config
  schema: {
    types: [timeline, milestone],
  },
})

Common errors to watch for:

The defineType function gives you TypeScript autocomplete and helps catch errors early, so always use it even though it's technically optional! If you're still getting errors, double-check that you've registered your types in the schema array and that all your imports are correct.

Show original thread
11 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions