`useQuery` returning type `never`
I have a monorepo with PNPM workspaces and TS project references and in one package
@ns/convex
I have all the Convex code and in another @nx/nextjs-app
I develop my Next.js client. Everything works well, except that TypeScript infers useQuery
's return type to never
.
Has anyone else encountered this? Got any idea how to solve it?9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Same happens if I explicitly type
messages
or handler
:
But if the type doesn't use anything that comes from the data model (schema), then it weirdly enough works:
FYI, if I import dataModel.d.ts
in the Next.js app, the Doc
type also resolves to never
:
For context, here's the schema.ts
:
That's really odd. I'd start with the basics - restart typescript language server, nuke node_modules and reinstall.
If it persists, I'd wonder how the generated api.js and api.d.ts files look. What happens when you hover the query itself, does the return type look right there?
Yeah, I tried those things as well (nuking node_modules, restarting TS language server) but it didn't help 😅
Here's api.js and api.d.ts

It shows the correct type when hovering over the query itself

Another interesting thing is that when running
tsc --build
for the Next.js app project, I get a type error
which doesn't show up in the editor. So there's inconsistency between tsc
and editor integration as well.
(FYI, I have set up "typescript.tsdk"
to point to node_modules
TS SDK.)
So at compile-time, TypeScript seems to think api
is just an empty object??
Update: it started working once I disabled TS project references for the convex project (@nx/convex
which contained Convex code and was being imported from by @ns/nextjs-app
which contained Next.js app code). So I set "composite"
, "declarationMap"
and "emitDeclarationOnly"
to false
in the project's tsconfig
s and dereferenced the project everywhere else (removed from "references"
of root tsconfig
and the Next.js app's tsconfig
).Thanks for following up with a solution - any drawbacks?
No noticeable drawbacks