Sanity TypeGen is now generally available
Written by Kristoffer Brabrand, Sindre Gulseth, Knut Melvær
AI coding tools are only as good as the context you give them. Point Claude, Cursor, or Copilot at vague, or no, types and you get vague suggestions. Give them precise types and they autocomplete correctly, catch edge cases, and stop hallucinating field names.
Sanity TypeGen generates precise TypeScript types from your content schemas and GROQ queries. Which means that you (and your agents) get the most out of the flexbility of GROQ, without losing the power of a well-defined schema. Few, if any, CMSes out there give you this developer experience.
So instead of event.format: string, you get 'in-person' | 'virtual'. Instead of post.coverImage: any, you get the full image structure with asset reference and optional alt text. Your editor autocompletes GROQ projections. Your AI assistant stops inventing fields (🤞). Your types stay in sync with your content model.
TypeGen is now generally available in Sanity Studio v5 with automatic regeneration, consolidated configuration, and stable APIs. If you used the beta, the migration is straightforward, the breaking changes are intentional improvements that make generated types more accurate.
Types that stay in sync while coding
The most requested feature during the beta was automation. Manually running sanity schema extract and sanity typegen generate every time you changed a schema or query worked, but it was easy to forget and end up with stale types.
Now you can turn on automatic type generation with a single config option. When you enable typegen.enabled: true, TypeGen will run automatically during sanity dev: