Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

TypeScript fails with error TS7022 when using SDK function results in subsequent calls (e.g., cursor pagination), due to circular type inference from implicit return types.

// Before: implicit return type causes circular reference
let cursor: string | undefined = undefined;
do {
  const { data, error } = await listDevices({
    client,
    query: { cursor }  // TS7022: implicitly has type 'any'
  })
  if (data?.links?.next) cursor = data.links.next;
} while (cursor);

Changes

  • Register RequestResult type from client module as external import
  • Generate explicit return types for SDK functions: RequestResult<TResponses, TErrors, ThrowOnError, TResponseStyle?>
  • Apply only to non-Nuxt clients (different return type structure)

Result

Generated functions now have explicit return type annotations:

import type { RequestResult } from './client';

export const listDevices = <ThrowOnError extends boolean = false>(
  options?: Options<ListDevicesData, ThrowOnError>
): RequestResult<ListDevicesResponses, unknown, ThrowOnError> => {
  return (options?.client ?? client).get<...>({...});
};

Pagination and similar patterns now work without type errors.

Original prompt

This section details on the original issue you should resolve

<issue_title>Typing dies when using result in query parameters</issue_title>
<issue_description>### 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</issue_description>

Comments on the Issue (you are @copilot in this section)

@mrlubos @TimVosch do you have a reproducible example?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

⚠️ No Changeset found

Latest commit: c49afff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Oct 31, 2025 4:06pm

…nference

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix typing issues when using result in query parameters Fix circular type inference in SDK functions with explicit return types Oct 31, 2025
Copilot AI requested a review from mrlubos October 31, 2025 16:13
Copilot finished work on behalf of mrlubos October 31, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing dies when using result in query parameters

2 participants