Configuring TypeGen in Sanity CLI config
As of version 4.19.0 it is recommended to configure typegen through the Sanity CLI config.
Starting with Sanity CLI v4.19.0, configure type generation in sanity.cli.ts by setting the TypeGen properties under the typegen field.
Before v4.19.0, you configured TypeGen in a separate file, sanity-typegen.json. That file is deprecated, and the CLI prints a warning when it finds one.
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: '<your-project-id>',
dataset: '<your-dataset>',
},
typegen: {
path: './src/**/*.{ts,tsx,js,jsx}', // glob pattern to your TypeScript files. Can also be an array of paths
schema: 'schema.json', // path to your schema file, generated with the 'sanity schema extract' command
generates: './sanity.types.ts', // path to the output file for generated type definitions
overloadClientMethods: true, // set to false to disable automatic overloading of the Sanity client
},
})Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?