Skip to content

fix(sdk): don't expose SSE errors as iterator return types#3989

Merged
mrlubos merged 2 commits into
hey-api:mainfrom
frastefanini:fix/sdk-sse-return-type
Jun 3, 2026
Merged

fix(sdk): don't expose SSE errors as iterator return types#3989
mrlubos merged 2 commits into
hey-api:mainfrom
frastefanini:fix/sdk-sse-return-type

Conversation

@frastefanini
Copy link
Copy Markdown
Contributor

@frastefanini frastefanini commented Jun 3, 2026

Closes #3990

Summary

Follow-up to #3919.

#3919 correctly fixed generated client SseFn types so endpoint HTTP errors are no longer threaded into ServerSentEventsResult's second generic slot. That slot is AsyncGenerator's TReturn, not an error channel.

However, the SDK return type builder still emits the old SSE shape:

Promise<ServerSentEventsResult<Responses, Errors | void, ThrowOnError>>

while generated clients now return:

Promise<ServerSentEventsResult<Responses>>

This makes generated SDK functions fail TypeScript assignability checks for SSE endpoints with concrete error responses.

Change

For SSE operations, the SDK return annotation now mirrors the client result shape:

Promise<ServerSentEventsResult<Responses>>

The generated call expression still passes <Responses, Errors, ThrowOnError> into client.sse.* to preserve compatibility with the current SseFn generic arity introduced/preserved by #3919.

Updated generated snapshots covering:

  • the main 3.1.x SSE client fixtures for Angular, Axios, Fetch, Next.js, and ofetch
  • the TanStack Query SSE fixture
  • the SDK opencode fixtures for flat, grouped, and export-all outputs

Nuxt is unchanged because its SSE type shape is different: it wraps RequestResult inside ServerSentEventsResult rather than passing the HTTP error type as TReturn.

Why

HTTP errors are not the async iterator completion value. They are handled by the initial request promise / SSE error hooks. The public SDK return type should therefore not expose endpoint error types through ServerSentEventsResult's TReturn.

Test plan

  • pnpm vitest run across @test/openapi-ts-sdks, @test/openapi-ts, @test/openapi-ts-tanstack-query-v5
  • pnpm typecheck
  • pnpm lint:fix

@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

@frastefanini is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug 🔥 Broken or incorrect behavior. labels Jun 3, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 3, 2026

🦋 Changeset detected

Latest commit: 2a458c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 39.21%. Comparing base (82e9f18) to head (2a458c3).

Files with missing lines Patch % Lines
...pi-ts/src/plugins/@hey-api/sdk/shared/operation.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3989   +/-   ##
=======================================
  Coverage   39.21%   39.21%           
=======================================
  Files         607      607           
  Lines       21468    21468           
  Branches     6345     6345           
=======================================
  Hits         8418     8418           
  Misses      10626    10626           
  Partials     2424     2424           
Flag Coverage Δ
unittests 39.21% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 3, 2026

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@3989

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@3989

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@3989

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@3989

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@3989

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@3989

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@3989

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@3989

commit: 2a458c3

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — This PR fixes the SDK return type for SSE operations so endpoint error types are no longer threaded into ServerSentEventsResult's TReturn generic slot (the async generator return type). It is a follow-up to #3919, which fixed the generated client SseFn types but left the SDK return type builder emitting the old shape.

  • Shorten SSE SDK return typePromise<ServerSentEventsResult<Responses, Errors | void, ThrowOnError>> is replaced by Promise<ServerSentEventsResult<Responses>> in operationReturnType().
  • Preserve call-site arity — The generated call expression still passes <Responses, Errors, ThrowOnError> into client.sse.* for compatibility with the current SseFn generic arity.
  • Update snapshots — Covers main 3.1.x SSE fixtures (Angular, Axios, Fetch, Next.js, ofetch), TanStack Query SSE fixture, and SDK opencode fixtures (flat, grouped, export-all).
  • Leave Nuxt unchanged — Nuxt's SSE shape differs (error flows through RequestResult, not TReturn).

Pullfrog  | View workflow run | Using Kimi K2𝕏

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — This PR fixes the SDK return type for SSE operations so endpoint error types are no longer threaded into ServerSentEventsResult's TReturn generic slot (the async generator return type). It is a follow-up to #3919, which fixed the generated client SseFn types but left the SDK return type builder emitting the old shape.

  • Shorten SSE SDK return typePromise<ServerSentEventsResult<Responses, Errors | void, ThrowOnError>> is replaced by Promise<ServerSentEventsResult<Responses>> in operationReturnType().
  • Preserve call-site arity — The generated call expression still passes <Responses, Errors, ThrowOnError> into client.sse.* for compatibility with the current SseFn generic arity.
  • Update snapshots — Covers main 3.1.x SSE fixtures (Angular, Axios, Fetch, Next.js, ofetch), TanStack Query SSE fixture, and SDK opencode fixtures (flat, grouped, export-all).
  • Leave Nuxt unchanged — Nuxt's SSE shape differs (error flows through RequestResult, not TReturn).

Pullfrog  | View workflow run | Using Kimi K2𝕏

Copy link
Copy Markdown
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thank you @frastefanini!

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 3, 2026
@mrlubos mrlubos merged commit 174e42f into hey-api:main Jun 3, 2026
9 of 11 checks passed
@hey-api hey-api Bot mentioned this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Broken or incorrect behavior. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.98: SSE SDK return annotation passes ThrowOnError as AsyncGenerator TNext, breaking for-await (TS2763)

2 participants