> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Migrating from experimental TypeGen in App SDK

Learn how to use Sanity TypeGen with the App SDK for type-safe document and query hooks.

Unlike the deprecated experimental package, TypeGen doesn't currently infer types automatically when you call a hook. You generate types from your schema, then pass them explicitly through the hooks' generics.

To use TypeGen, keep a `sanity.config.ts` plus schema in your app directory (as with the experimental version).

## Single project and dataset

Uses TypeGen's defaults — no config needed.

```bash
sanity schema extract      # → schema.json
sanity typegen generate    # → sanity.types.ts
```

## Multiple resources

Make a workspace and schema for each project/dataset pair (the `sanity.cli.ts` typegen block holds only one schema, so use a config file per resource; you may receive a deprecation warning).

```bash
sanity schema extract --workspace primary   --path schema.primary.json
sanity schema extract --workspace secondary --path schema.secondary.json
```

Add the typegen config files, like this:

**typegen.primary.json**

```json
{
  "schema": "./schema.primary.json",
  "generates": "./sanity.types.primary.ts",
  "path": "./src/**/*.{ts,tsx,js,jsx}"
}
```

```bash
sanity typegen generate --config-path typegen.primary.json
sanity typegen generate --config-path typegen.secondary.json
```

## Use the generated types

Import and pass them via the hook generics:

```typescript
import type {Movie} from './sanity.types.primary'

const {data} = useDocument<Movie>({...movieHandle})
```

## Limitations

Standard TypeGen generates result types for `defineQuery` queries but has no access to `defineProjection` that the experimental version does. For typed projection data, either type it by hand or use a `useQuery` with `defineQuery` and pass its generated result type.

