Skip to content

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

@nisharg-codal

Description

@nisharg-codal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions