惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
M
MIT News - Artificial intelligence
GbyAI
GbyAI
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
IT之家
IT之家
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
爱范儿
爱范儿
N
Netflix TechBlog - Medium
U
Unit 42
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 叶小钗
G
Google Developers Blog
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
腾讯CDC

Sanity.io

A Board Game agent built using Sanity Context and Vercel's AI SDK | Sanity Build a prototype with Claude Code that your whole team can edit | Sanity What’s New - May 2026 | Sanity I built a London pub guide with v0 and the Sanity MCP in six hours. Here's what I learned. | Sanity Build a conference concierge with Agent Context and Anthropic | Sanity Build a content-aware Telegram agent with Vercel AI SDK and Chat SDK | Sanity How I used Agent API to generate photos for my family’s recipes | Sanity What’s New April - 2026 | Sanity Better context, better matches: An AI love story (for dogs) | Sanity How to write for an agent | Sanity Content Agent, meet Slack: AI content operations in your workflow | Sanity Structure powers intelligence | Sanity Your agent needs better content. Here's how to give it. | Sanity How to serve content to agents (a field guide) | Sanity Sanity is now available on the Vercel Marketplace | Sanity The logo soup problem (and how to solve it) | Sanity Content Releases: From scattered updates to coordinated publishing | Sanity What's New - February 2026 | Sanity How we solved the agent memory problem | Sanity v0 Builder Challenge: The winners | Sanity Introducing: Sanity Agent Skills | Sanity Content Agent: Days of work in one conversation | Sanity Our Sanity Values | Sanity Open Source Pledge 2025: Stepping up when it matters | Sanity v0 builder challenge: $3000 in prizes | Sanity Why AI Breaks Without Structured Content Operations | Sanity What’s New January - 2026 | Sanity BFCM 2025: What teams built when infrastructure stopped being the problem | Sanity How AI shaped holiday shopping and what it means for content in 2026 | Sanity Sanity Studio v5: Embracing React 19 | Sanity
Sanity TypeGen GA: Automatic TypeScript types for content...
Knut Melvær · 2026-02-17 · via Sanity.io

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:

Running sanity dev now watches your schema and query files automatically. If you're running a separate frontend repo, use the --watch flag:

One config file, not two

TypeGen originally had sanity-typegen.json for configuration. Now everything lives in sanity.cli.ts alongside your other CLI settings.

The old config file still works but now shows a deprecation warning.

One caveat: if you’re in a mono repo where the studio and other apps are in different packages, you'll still need the JSON schema for those:

  • Enable schemaExtraction.enabled: true in the studio's sanity.cli.ts to produce the schema.json.
  • Then point your frontend/apps repo's typegen config at that generated schema file.

Faster generation (with a progress bar, finally)

We rewrote the type generation internals with memoization, so updates in watch mode are significantly faster. You'll also see a progress indicator during generation so you know it's working. (No, we can’t promise we have finaly solved the halting problem.)

Smarter generated output

The generated types are now more accurate and easier to work with:

  • Preserved casing: A query named MyPageQuery now produces MyPageQueryResult instead of MypagequeryResult
  • Correct non-identifier keys: Fields with kebab-case or special characters are now properly quoted
  • Smaller output: Array types now use an ArrayOf utility type, reducing duplication and file size

Type utilities for real-world schemas

Two new utility types make it easier to work with complex content models. This is especially handy for landing page-type content that tends to get nested.

The Get utility extracts deeply nested properties (up to 20 levels):

The FilterByType utility pulls specific types from unions using the _type discriminator:

Framework support beyond Next.js

The TypeGen tooling now supports @sanity/sveltekit defineQuery imports and can parse .svelte and .vue files. Support for .astro files was already available.

What “GA” means (and what it doesn't)

General availability means the TypeGen APIs are stable. The configuration format, CLI commands, and utility types won't change in breaking ways. Generated output will continue to improve, but those improvements will remain compatible with your existing code.

Some limitations remain:

Getting started

Setup depends on your project structure. Here are the three most common scenarios:

If you're running sanity dev or sanity build in your studio

In your studio, you typically want schema extraction enabled to generate the schema.json file. If you only need the schema.json (for example, to use in other packages), enable schemaExtraction.enabled: true. If you also need types in your studio code (for custom components, etc.), add typegen.enabled: true as well. Both control whether these processes run as part of sanity dev and sanity build commands.

Monorepo with separate studio and frontend packages

In your studio's sanity.cli.ts, enable schemaExtraction.enabled: true to generate the schema.json file when you run sanity dev or sanity build. Add typegen.enabled: true if you also want to generate types for use in the studio itself.

In your frontend packages, run sanity typegen generate --watch and configure the path to point to the schema.json generated by the studio. Since frontend repos don't use sanity dev or sanity build, you run the typegen command directly with the --watch flag for automatic regeneration during development.

Studio embedded in another app

If your Studio is embedded on an app route (Next.js, Astro, Nuxt, etc.), you're not using sanity dev or sanity build to build your app. This means the enabled flags won't help you. Instead, you'll need to run the CLI commands directly:

  • sanity schema extract to generate the schema JSON
  • sanity typegen generate to create types (use --watch for automatic regeneration during development)

Migrating from the beta

If you're using the beta, here's the migration path:

  1. Update to Sanity Studio v5
  2. Move config from sanity-typegen.json to sanity.cli.ts
  3. Regenerate types (expect diffs due to improvements)
  4. Enable automatic generation with enabled: true

The breaking changes are intentional corrections that make the generated types more accurate.

Everything that changed since beta

Here’s the smørgåsbord of most of the things we improved:

  • Automatic type generation during sanity dev and sanity build
  • Configuration moved to sanity.cli.ts
  • Progress indicator during generation
  • Memoization for faster watch mode updates
  • Preserved casing in generated type names
  • Proper quoting for non-identifier keys
  • ArrayOf utility type for smaller output
  • Get utility for extracting nested types (up to 20 levels)
  • FilterByType utility for filtering union types
  • Support for @sanity/sveltekit defineQuery
  • Parsing support for .svelte and .vue files
  • @sanity-typegen-ignore comment support
  • Stable API surface (no more breaking changes planned)

The Sanity Learn course has been updated to reflect all these changes. If you're new to TypeGen or want to see the latest features in action, it's a great place to start.

Thanks to Kristoffer Brabrand, Rico Kahler, and Sindre Gulseth for the work here. And to everyone who tested the beta and provided feedback. If you run into issues or have suggestions, join us in the #typescript channel in the Sanity community Discord.