Sanity TypeGen is now generally available
Blog post from Sanity
Sanity TypeGen, now generally available in Sanity Studio v5, automates the generation of precise TypeScript types from content schemas and GROQ queries, enhancing developer experience by maintaining type synchronization with content models. The tool replaces manual configurations and updates with an automated process enabled via a single configuration option in the sanity.cli.ts file, making it easier for developers to handle complex content schemas. Key improvements include faster type generation through memoization, a progress indicator, and more accurate generated outputs with preserved casing and properly quoted non-identifier keys. TypeGen supports multiple frameworks beyond Next.js, including SvelteKit, Vue, and Astro, and offers utility types like Get and FilterByType for efficient handling of nested and union types. While the API surface is stable, some limitations exist, such as the handling of cross-dataset references and custom GROQ functions. The migration from the beta version involves updating configurations and enabling automatic type generation, with improvements aimed at making the types more precise and reducing file sizes.