openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

Typing dies when using result in query parameters

Open TimVosch opened this issue 1 month ago • 2 comments

Description

@hey-api/openapi-ts v0.86.11 "@hey-api/client-fetch": "^0.13.1" "typescript": "~5.9.3"

I wanted to create a quick pagination script that grabs the cursor from the result and uses it in the query parameters again, but this seems to break the typings alltogether:

Diagnostics:
1. 'res' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. [7022]
import { listDevices } from "./lib/api";
import { createClient } from "./lib/api/client";

const client = createClient({})

let cursor: string | undefined = undefined;
do {
  const { data, error } = await listDevices({
    client,
    query: {
      cursor,
    }
  })
  if (!data && error) throw new Error("Borken: ", error)

  if (data?.links?.next) cursor = URL.parse(data.links.next)?.searchParams.get("cursor") || undefined;
} while (cursor);
openapi-ts -i ./api.yaml -o src/lib/api -c @hey-api/client-fetch

Reproducible example or configuration

No response

OpenAPI specification (optional)

openapi: 3.0.0
info:
  title: Example API
  version: '0.0.1'
servers:
  - description: Production
    url: 'https://sensorbucket.nl/api'
  - description: Localhost
    url: 'http://localhost:3000/api'
paths: 
  /devices:
    get:
      operationId: ListDevices
      summary: List devices
      description: |
        Fetch a list of devices.
      tags: ["Core"]
      parameters:
        - in: query
          name: cursor
          description: The cursor for the current page
          required: false
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  actualData:
                    type: object
                  links:
                    type: object
                    properties:
                      next:
                        type: string

System information (optional)

No response

TimVosch avatar Oct 31 '25 08:10 TimVosch

@TimVosch do you have a reproducible example?

mrlubos avatar Oct 31 '25 12:10 mrlubos

@mrlubos

@TimVosch do you have a reproducible example?

yes: https://github.com/TimVosch/heyapi-typing-issue

I have noticed the following, perhaps i am missing something obvious or typescript is being whacky.

Breaks...

let cursor: string | undefined = undefined;

Doesn't break?

let cursor: string | undefined;

TimVosch avatar Oct 31 '25 15:10 TimVosch