NEEGHANN
Convex Community9mo ago
12 replies
NEEGHAN

`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.

// in packages/convex/src/chat.ts
export const getMessages = query({
  handler: async (ctx) => {
    const messages = await ctx.db.query("chat_messages").collect();
    return messages;
  },
});


// in packages/nextjs-app/src/components/Chat.tsx
export const Chat = () => {
  const messages = useQuery(api.chat.getMessages);
  //    ^
  //    TypeScript infers this to `never[] | undefined`
  ...
};


Has anyone else encountered this? Got any idea how to solve it?
Was this page helpful?