When generating types using Sanity, the output file includes helper types that are not referenced anywhere in the file. This causes TypeScript builds to fail when noUnusedLocals is enabled.
Example error:
error TS6196: 'ArrayOf' is declared but never used.
File:
Example snippet:
type ArrayOf<T> = Array<
T & {
_key: string;
}
>;
This type is never used, which breaks strict TypeScript setups.
Steps to reproduce:
- Enable
noUnusedLocals: true in tsconfig.json
- Generate Sanity types
- Run
tsc
Expected behavior:
Generated files should:
- Not contain unused types, or
- Be safe to compile under strict TypeScript settings, or
Actual behavior:
TypeScript fails with TS6196 due to unused generated types.
Environment:
- Sanity version: ^5.7.0
- TypeScript version: ^5.9.3
- OS: macOS
- Package manager: pnpm
- Monorepo: Turborepo