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.
Description
Since v0.98.0 (explicit SDK return types for isolatedDeclarations), SSE operations are annotated as:
ServerSentEventsResultis declared as<TData, TReturn = void, TNext = unknown>, soThrowOnErrorlands inAsyncGenerator'sTNext. With the defaultThrowOnError = true, consuming the stream fails:TReturn = Errors | voidalso doesn't match the runtime:createSseClientreturnsServerSentEventsResult<TData>(generator returns void; errors go throughonSseError/throw, not the generator return value).Emission site:
operationReturnTypein the sdk plugin —Annotating just
Promise<ServerSentEventsResult<responses>>matches the bundled client and fixes the consumer-side error.Reproducible?
Any spec with an SSE operation (
text/event-streamresponse),@hey-api/client-fetch+@hey-api/sdk, v0.98.0/0.98.1; iterate the returnedstreamunder strict TypeScript.Workaround
Pin to 0.97.x.