sanity-io / next-sanity

Sanity.io toolkit for Next.js
https://www.sanity.io/
MIT License
760 stars 91 forks source link

Generating TS types not working when importing defineQuery from next-sanity #1654

Open Jdruwe opened 2 months ago

Jdruwe commented 2 months ago

I was reading the updated docs on generating types: https://github.com/sanity-io/next-sanity?tab=readme-ov-file#generate-typescript-types. I updated both next-sanity & sanity to the latest versions and tried generating the types. I noticed that when I import define query like this, it doesn't work

import { defineQuery } from 'next-sanity';

When I import it directly from groq it does work:

import { defineQuery } from 'groq';

Expected behavior

image

Correct return type VS:

image

Notice Promise of the actual result vs any when using defineQuery from next-sanity.

stipsan commented 1 week ago

Does it work again if you install @sanity/client explicitly? We've seen that with some package managers, like pnpm, peer dependencies are not hoisted by default. And our auto type gen which uses declare module "@sanity/client" doesn't work, since you don't have a ./node_modules/@sanity/client folder 🤔