mirror of
https://github.com/sanity-io/agent-toolkit.git
synced 2026-09-14 18:39:20 +08:00
68c5283f7d
Fixes from final review pass by DX and TypeScript expert agents: - Added "unique query names" requirement (common developer footgun) - Added tsconfig includes requirement for sanity.types.ts - Fixed AUTHOR_QUERY example: was array query used as single object - Added .astro, .svelte, .vue to path glob examples - Updated Astro rule to use defineQuery instead of raw strings - Updated get-started guide to use defineQuery (was raw string) - Updated GROQ maintenance workflow to mention automatic generation - Updated AGENTS.md boundary to mention typegen.enabled option - Fixed groq-define-query.md to show auto-inference as primary pattern - Standardized import path to @/sanity.types Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.8 KiB
1.8 KiB
name, description
| name | description |
|---|---|
| typegen | Run Sanity TypeGen and troubleshoot type generation issues. |
Sanity TypeGen Workflow
I'll help you generate TypeScript types from your Sanity schema.
Quick Start
npm run typegen
# or
npx sanity schema extract && npx sanity typegen generate
What I'll Do
-
Check Configuration
- Check for
typegenconfig insanity.cli.ts(recommended) - If using deprecated
sanity-typegen.json, suggest migrating tosanity.cli.ts - Ensure
typegenscript is inpackage.json(for manual workflows)
- Check for
-
Run TypeGen
- Execute the typegen command
- Report any errors
-
Troubleshoot Issues
- Fix incorrect path globs
- Resolve schema syntax errors
- Update query imports
- Migrate deprecated
sanity-typegen.jsontosanity.cli.ts
Common Issues I Fix
| Issue | Solution |
|---|---|
| "No schema found" | Fix path glob in sanity.cli.ts typegen config |
| "Query not typed" | Wrap in defineQuery() or groq template |
| Types outdated | Re-run after schema/query changes, or enable automatic generation |
| Import errors | Check sanity.types.ts output path |
Using sanity-typegen.json |
Migrate config to sanity.cli.ts (deprecated) |
Configuration
Configure TypeGen in sanity.cli.ts:
// sanity.cli.ts
import { defineCliConfig } from 'sanity/cli'
export default defineCliConfig({
typegen: {
enabled: true, // Auto-generate during sanity dev/build
path: "./src/**/*.{ts,tsx,js,jsx,astro,svelte,vue}",
schema: "schema.json",
generates: "./sanity.types.ts",
overloadClientMethods: true,
},
})
Usage
"Run typegen" "Fix my TypeGen configuration" "Why are my types not updating?" "Enable automatic type generation"