Skip to content

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

@AlphaJack

Description

@AlphaJack

Description

Since v0.98.0 (explicit SDK return types for isolatedDeclarations), SSE operations are annotated as:

export const sendMessage = <ThrowOnError extends boolean = true>(
  options: Options<SendMessageData, ThrowOnError, unknown>
): Promise<ServerSentEventsResult<SendMessageResponses, SendMessageErrors | void, ThrowOnError>> => ...

ServerSentEventsResult is declared as <TData, TReturn = void, TNext = unknown>, so ThrowOnError lands in AsyncGenerator's TNext. With the default ThrowOnError = true, consuming the stream fails:

const { stream } = await sendMessage({ ... });
for await (const data of stream) { ... }
// TS2763: Cannot iterate value because the 'next' method of its iterator
// expects type 'true', but for-of will always send 'undefined'.

TReturn = Errors | void also doesn't match the runtime: createSseClient returns ServerSentEventsResult<TData> (generator returns void; errors go through onSseError/throw, not the generator return value).

Emission site: operationReturnType in the sdk plugin —

if (isSse) return $.type('Promise').generic(
  sseResult.generic(queryType('responses'))
    .generic($.type.or(queryType('errors'), $.type('void')))
    .generic('ThrowOnError'),
);

Annotating just Promise<ServerSentEventsResult<responses>> matches the bundled client and fixes the consumer-side error.

Reproducible?

Any spec with an SSE operation (text/event-stream response), @hey-api/client-fetch + @hey-api/sdk, v0.98.0/0.98.1; iterate the returned stream under strict TypeScript.

Workaround

Pin to 0.97.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions