Generated sanity.types.ts contains unused types causing TypeScript build failures (TS6196)

Open
#34 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start by tracing the generator that produces sanity.types.ts, then reproduce the issue with noUnusedLocals enabled in tsconfig.json and run tsc. Done means generated TypeScript no longer fails with TS6196 for unused helper types while preserving the generated output’s intended use.

Written by the indexing model from the issue text.

Description

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:

sanity.types.ts

Example snippet:

type ArrayOf<T> = Array<
  T & {
    _key: string;
  }
>;

This type is never used, which breaks strict TypeScript setups.

Steps to reproduce:

  1. Enable noUnusedLocals: true in tsconfig.json
  2. Generate Sanity types
  3. 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
Dominant language
TypeScript
Stars
1
Forks
2
Avg merge
3d 11h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sanity-io/codegen

All issues in sanity-io/codegen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.