Skip to content

useQuery query options allow unknown key values #1338

@lexer21

Description

@lexer21

Environment

Node v22.15.0
orpc v1.13.2

Reproduction

NestJS + orpc example: https://github.com/unnoq/orpc/tree/main/playgrounds/nest

Describe the bug

When running the example NestJS repo and trying to use the orpc client with useQuery the input objects accepts any key values. Is this intentional or a bug?

From the provided NestJS example code

// contract/planet.ts
export const listPlanets = oc
  .route({
    method: 'GET',
    path: '/planets',
    summary: 'List all planets',
    tags: ['Planets'],
  })
  .input(
    z.object({
      limit: z.number().int().min(1).max(100).default(10),
      cursor: z.number().int().min(0).default(0),
    }),
  )
  .output(z.array(PlanetSchema))


// playground-tanstack-query.ts
import { orpc } from './lib/orpc'
import { useQuery } from '@tanstack/react-query'
const {data} = useQuery(orpc.planet.list.queryOptions({input: {cursor: 1, limit: 12, test: "123"}}))

In the above code TS compiler does not raise a error Object literal may only specify known properties for key value test: "123" eventhough it is not defined in the contract. However if I use useMutation. In the mutate function, it does raise an error if I provide an unknown key value. Comming from trpc this is very unintuitive for me since there when using useQuery with trpc client i would allways get an error if specifying unknown values for the input.

Image

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions