sanity-typegen

Troubleshoot and setup Sanity TypeGen configuration. Use when types are missing or incorrect.

⭐37stars🔀3forks📁View on GitHub🕐Updated Dec 18, 2025⬇️2downloads

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.
namesanity-typegen
descriptionTroubleshoot 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

  1. Check Configuration

    • Check if sanity-typegen.json exists.
    • If missing, ask: "Do you want me to set up Sanity TypeGen?"
    • If yes, create the file based on sanity://rules/sanity-typegen.mdc.
  2. Check Scripts

    • Read package.json.
    • Ensure a typegen script exists: "sanity schema extract && sanity typegen generate".
    • If missing, add it.
  3. Run & Verify

    • Run npm run typegen.
    • If it fails, read the error log and fix the sanity-typegen.json paths (often the path glob is incorrect for the project structure).
    • If successful, confirm that sanity.types.ts (or configured output) was updated.