TypeGen CLI command reference

Generate TypeScript type definition from a Studio schema and GROQ queries

New to the TypeGen?

This is reference documentation for the CLI's typegen command. If you're new to TypeGen, check out our getting started guide.

npx sanity typegen --help

Commands

generate

USAGE
  $ sanity typegen generate [--config-path <value>] [--watch]

FLAGS
      --config-path=<value>  [Default: sanity-typegen.json] Specifies the path to the typegen configuration file. This file should be a JSON file that contains settings for the type generation process.
      --watch                [Default: false] Run the typegen in watch mode

DESCRIPTION
  Sanity TypeGen
  
  Configuration:
  This command can utilize configuration settings defined in a `sanity-typegen.json` file. These settings include:
  
  - "path": Specifies a glob pattern to locate your TypeScript or JavaScript files.
    Default: "./src/**/*.{ts,tsx,js,jsx}"
  
  - "schema": Defines the path to your Sanity schema file. This file should be generated using the `sanity schema extract` command.
    Default: "schema.json"
  
  - "generates": Indicates the path where the generated TypeScript type definitions will be saved.
    Default: "./sanity.types.ts"
  
  The default configuration values listed above are used if not overridden in your `sanity-typegen.json` configuration file. To customize the behavior of the type generation, adjust these properties in the configuration file according to your project's needs.
  
  Note:
  - The `sanity schema extract` command is a prerequisite for extracting your Sanity Studio schema into a `schema.json` file, which is then used by the `sanity typegen generate` command to generate type definitions.
  - To generate types for several datasets, list them in `typegen.resources` in `sanity.cli.ts` (beta). Each resource uses its own `schema` file, or the schema bound to its dataset when `schema` is omitted.

EXAMPLES
  Generate TypeScript type definitions from a Sanity Studio schema extracted using the `sanity schema extract` command.

    $ sanity typegen generate

Was this page helpful?

sanity.ioAll Systems Operational© Sanity 2026
Change site theme