Skip to content

[Tanstack-Query] queryOptionstype definitions allow passing procedure inputs at the top level, leading to silent failures #952

@jlucaso1

Description

@jlucaso1

Environment

"@orpc/client": "^1.8.5"
"@orpc/server": "^1.8.5"
"@orpc/tanstack-query": "^1.8.5"

Node 22

Reproduction

const listUsersInputSchema = z.object({
  page: z.number().optional().default(1),
  query: z.string().optional().default(''),
});

export const usersRouter = {
  list: publicProcedure
    .input(listUsersInputSchema)
    .handler(async ({ input }) => {
      // Logic to fetch users based on input.page and input.query
      console.log('Fetching with input:', input);
      return { users: [], total: 0 };
    }),
};
import { useQuery } from '@tanstack/react-query';
import { rpc } from './rpc-client';

function UserTable() {
  const activeQuery = 'some-search-term';

  // ❌ This code is functionally WRONG, but TypeScript thinks it's OK.
  // The `page` and `query` props are silently ignored.
  const { data, isLoading } = useQuery(
    rpc.users.list.queryOptions({
      query: activeQuery,
      // The `input` key is missing!
    })
  );
}
// ✅ This is the correct way to call it.
const { data, isLoading } = useQuery(
  rpc.users.list.queryOptions({
    input: { // Correctly nested
      query: activeQuery,
    },
  })
);

Describe the bug

It's easy for a developer to accidentally pass a procedure's input arguments at the top level of the queryOptions object, instead of nesting them under the input key.
When this happens, TypeScript doesn't raise any errors. The query still runs, but it silently ignores the inputs, leading to incorrect behavior (in my case, a search filter not working)

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginvalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions