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

Reusing field definitions across Sanity schema documents

11 repliesLast updated: Nov 29, 2025

Could I do something like this?
export default {
  name: 'Foo',
  type: 'document',
  fields: [title, description],
};

// And then have title and description somewhere else:

const title = {
  name: 'title',
  type: 'string',
  validation: (Rule) => Rule.required().error('The title is required.'),
};

const description = {
  name: 'description',
  type: 'text',
  validation: (Rule) => Rule.required().error('The description is required.'),
};
AI Update

Yes, absolutely! You can definitely do something like that in Sanity. This is a great pattern for creating reusable field definitions.

What you're showing is extracting field definitions into separate constants and then spreading them into your schema. This works perfectly in Sanity and is actually a recommended practice for keeping your schemas DRY (Don't Repeat Yourself).

Here's how you can do it:

// Define reusable fields
const title = {
  name: 'title',
  type: 'string',
  validation: (Rule) => Rule.required().error('The title is required.'),
};

const description = {
  name: 'description',
  type: 'text',
  validation: (Rule) => Rule.required().error('The description is required.'),
};

// Use them in your schema
export default {
  name: 'Foo',
  type: 'document',
  fields: [title, description],
};

Even better with TypeScript helpers:

If you're using TypeScript, you can use defineField for better type safety:

import {defineField, defineType} from 'sanity'

// Define reusable fields
const title = defineField({
  name: 'title',
  type: 'string',
  validation: (Rule) => Rule.required().error('The title is required.'),
});

const description = defineField({
  name: 'description',
  type: 'text',
  validation: (Rule) => Rule.required().error('The description is required.'),
});

// Use them in your schema
export default defineType({
  name: 'Foo',
  type: 'document',
  fields: [title, description],
});

Common use cases:

This pattern is especially useful when:

You can even organize these in a separate file like fields.ts and import them wherever needed!

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