sanity-typegen
Troubleshoot and setup Sanity TypeGen configuration. Use when types are missing or incorrect.
When & Why to Use This Skill
The sanity-typegen skill is a specialized developer utility designed to automate the setup and troubleshooting of Sanity TypeGen within TypeScript projects. It streamlines the integration between the Sanity Content Lake and your local codebase by ensuring configuration files are correctly placed, npm scripts are properly defined, and pathing errors are resolved, ultimately maintaining robust type safety and reducing manual debugging time.
Use Cases
- 1. Initial Project Configuration: Automatically detect missing Sanity TypeGen setups and generate the necessary sanity-typegen.json and package.json scripts for new projects.
- 2. Debugging Type Mismatches: Identify and fix broken TypeScript types by analyzing error logs and correcting invalid file path globs in the configuration.
- 3. Workflow Optimization: Ensure the 'sanity schema extract' and 'typegen generate' commands are correctly sequenced and executable to keep frontend types in sync with CMS schema changes.
| name | sanity-typegen |
|---|---|
| description | Troubleshoot and setup Sanity TypeGen configuration. Use when types are missing or incorrect. |
TypeGen Setup & Fixer
This skill ensures TypeScript types are generating correctly for the Content Lake.
Procedure
Check Configuration
- Check if
sanity-typegen.jsonexists. - If missing, ask: "Do you want me to set up Sanity TypeGen?"
- If yes, create the file based on
sanity://rules/sanity-typegen.mdc.
- Check if
Check Scripts
- Read
package.json. - Ensure a
typegenscript exists:"sanity schema extract && sanity typegen generate". - If missing, add it.
- Read
Run & Verify
- Run
npm run typegen. - If it fails, read the error log and fix the
sanity-typegen.jsonpaths (often thepathglob is incorrect for the project structure). - If successful, confirm that
sanity.types.ts(or configured output) was updated.
- Run