Skip to content

clientgen: add optional CallParameters to generated TypeScript endpoint methods#2436

Open
0x4A756E65 wants to merge 1 commit into
encoredev:mainfrom
0x4A756E65:feat/typed-endpoint-call-parameters
Open

clientgen: add optional CallParameters to generated TypeScript endpoint methods#2436
0x4A756E65 wants to merge 1 commit into
encoredev:mainfrom
0x4A756E65:feat/typed-endpoint-call-parameters

Conversation

@0x4A756E65

@0x4A756E65 0x4A756E65 commented May 8, 2026

Copy link
Copy Markdown

Generated TypeScript endpoint methods don't currently accept CallParameters, so there's no way to pass an AbortSignal through the generated client. Raw endpoints already support this — this brings typed endpoints to parity.

Without this, when a user navigates away from a page in a SPA, in-flight requests can't be canceled. The backend continues processing the abandoned request and logs "context canceled" errors when the response tries to write to a closed connection.

Before / After

// Before — no way to pass options
await client.svc.GetStatus(req)

// After — optional CallParameters as trailing argument
await client.svc.GetStatus(req, { signal: controller.signal })

Changes

  • pkg/clientgen/typescript.go: non-raw, non-stream endpoints now accept an optional trailing options?: CallParameters, forwarded to callTypedAPI. When headers/query are present, options are spread first ({...options, headers, query}) so endpoint-specific values take precedence.
  • 8 golden test files updated to match.
  • sharedTypes, stream, and raw code paths are unchanged.
  • Fully backwards-compatible.

…nt methods

Generated TypeScript service methods for non-raw, non-stream endpoints
now accept an optional `options?: CallParameters` trailing parameter,
which is forwarded to `callTypedAPI`. This allows callers to pass
an AbortSignal (or other fetch RequestInit options) per request.

A common scenario: when a React SPA uses TanStack Query, the library
provides an AbortSignal that fires when a component unmounts or a query
is invalidated. Without this change, there is no way to forward that
signal through the generated client, causing the backend to continue
processing abandoned requests and logging spurious "context canceled"
errors.

Usage example:

    const query = useQuery({
      queryKey: ["status"],
      queryFn: ({ signal }) =>
        client.myService.GetStatus(req, { signal }),
    });

When headers or query parameters are already present, the options
are spread into the existing params object (`{...options, headers, query}`)
so endpoint-specific values take precedence.

Raw endpoints already accepted CallParameters and are unchanged.
Stream endpoints are unchanged.
The sharedTypes code path is unchanged.
@0x4A756E65 0x4A756E65 marked this pull request as draft May 8, 2026 20:01
@0x4A756E65 0x4A756E65 marked this pull request as ready for review May 11, 2026 13:09
@0x4A756E65

Copy link
Copy Markdown
Author

Any interest here Encore team?

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.

1 participant