Schema changes not reflecting in output despite showing in Studio
This is a common issue with TypeScript types not updating after schema changes! When you modify your schema and can see the new fields in the Studio, but they're not showing up in your TypeScript types or query results, you need to regenerate your types.
Here's what you need to do:
1. Extract your updated schema:
npx sanity@latest schema extractThis creates/updates a schema.json file with your current schema structure.
2. Generate the TypeScript types:
npx sanity@latest typegen generateThis will create or update your sanity.types.ts file (or wherever your types are configured to be generated) with types for all your schema changes, including those new fields.
Why this happens:
The TypeScript types used in your frontend/queries are generated from a static snapshot of your schema, not directly from your Studio. When you change your schema, the Studio immediately reflects those changes, but your TypeScript definitions remain outdated until you regenerate them using the commands above.
Pro tip for development:
If you're frequently updating your schema during development, you might want to run these commands regularly or set up a watch process. Some developers add a script to their package.json:
{
"scripts": {
"typegen": "sanity schema extract && sanity typegen generate"
}
}Then you can just run npm run typegen whenever you make schema changes.
If you're working in a multi-folder project (like a separate frontend), make sure your sanity-typegen.json configuration file points to the correct paths for your schema and where the types should be generated.
You can learn more about this workflow in the Sanity TypeGen documentation or take the Typed content with Sanity TypeGen course.
Show original thread8 replies
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.