Skip to content

Sanity TypeGen with NextJS: the return type of queries is not correctly resolved #2218

@lucafaggianelli

Description

@lucafaggianelli

Describe the bug

When generating types definition via Sanity TypeGen in a NextJS project, the return type of queries is not correctly resolved.

Observing the generated types, they're all correct, but the @sanity/client import is not found (it's used in the declare module), the solution is either to install @sanity/client or use next-sanity in declare module.

To Reproduce

Steps to reproduce the behavior:

  1. Generate a new NextJS + Sanity project
  2. Follow the instruction to setup TypeGen
  3. Create a query
  4. The return type of the query is any

Expected behavior

The query return type should be defined and not any

Screenshots

Which versions of Sanity are you using?

@sanity/cli (global)  3.72.1 (up to date)
@sanity/image-url      1.1.0 (up to date)
@sanity/vision        3.72.1 (up to date)
sanity                3.72.1 (up to date)

What operating system are you using?

MacOS

Which versions of Node.js / npm are you running?

pnpm v9.9.0
v22.10.0

Additional context

Add any other context about the problem here.

Security issue?

Any security issues should be submitted directly to [email protected]. In order to determine whether you are dealing with a security issue, ask yourself these two questions:

  • Can I access something that's not mine, or something I shouldn't have access to?
  • Can I disable something for other people? If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, just email us at [[email protected]](mailto:[email protected].

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