fix(sdk): unbreak typecheck on dev after v2 error widening#28503
Merged
kitlangton merged 1 commit intoMay 20, 2026
Conversation
Two problems surfaced when anomalyco#28495 + the follow-up `chore: generate` populated previously-empty v2 error response unions. 1. `@hey-api/openapi-ts` codegen passes the endpoint's `TError` into the second generic of `ServerSentEventsResult`, which is the underlying `AsyncGenerator`'s `TReturn` slot — not an error channel. The SSE implementation's own signature uses `ServerSentEventsResult<TData>`, so it's only the public `SseFn` wrapper that's wrong. Latent for ~9 months; harmless while error unions were unknown, but breaks every `.return(undefined)` call and every mock async generator the moment an SSE endpoint declares a concrete error response. Patch the generated `client/types.gen.ts` and add a post-gen step in `script/build.ts` so every future `chore: generate` reapplies it. 2. `experimental.workspace.warp` now returns `InvalidRequestError` in its 400 union, which uses `_tag` rather than `name` as its discriminator. Narrow the error before reading `.name` in `dialog-workspace-create.tsx`. Verified end-to-end: `bun run build` in `packages/sdk/js` wipes and regenerates v2/gen, then re-applies the SseFn patch automatically; full monorepo typecheck and stream.transport tests are green.
Draft
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
devhas been red since commit0e118d1961(chore: generatefollowing #28495). Two distinct issues:1.
@hey-api/openapi-tsSseFnmiswiring (latent for ~9 months)In every generated client bundle, the SDK declares:
But
ServerSentEventsResult<TData, TReturn = void, TNext = unknown>— that second slot is the underlyingAsyncGenerator's return value type, not an error channel. HTTP errors are thrown from the initial promise or surfaced viaonSseError; an async generator's.return()value has nothing to do with them.Confirming this is the SDK's own bug, not intentional:
ServerSentEventsResult<TData>(noTError) — seeclient-core/bundle/serverSentEvents.ts:80-92.async function*with no explicit return → realTReturnisvoid.d43ef3f3b("feat(client): add support for server-sent events", Aug 2025).While the v2
GlobalEventErrorsunion was effectively empty/unknown this was harmless. PR #28495 widened error responses to concrete types, and now every.return(undefined)call and every mock async generator violates the iterator'sTReturncontract:Fix: drop
TErrorfrom theServerSentEventsResult<>generics in our generatedpackages/sdk/js/src/v2/gen/client/types.gen.tssoTReturndefaults tovoid. Because@hey-api/openapi-tsruns withclean: trueand would overwrite that file on every regen, add a post-gen patch step topackages/sdk/js/script/build.tsthat reapplies the fix automatically (and throws if the upstream output shape ever changes, so we'll notice). The phantomTErrorparameter onSseFnis preserved to keep call-site type-argument arity intact.I'll open an upstream PR to
hey-api/openapi-tsseparately so we can drop this workaround when it ships.2.
workspace.warp400 union widened to includeInvalidRequestErrorReal consumer bug, separate from #1.
ExperimentalWorkspaceWarpErrorsis nowWorkspaceWarpError | VcsApplyError | InvalidRequestError. The first two discriminate vianame, butInvalidRequestErroruses_tag(mixed conventions in the SDK). The dialog narrowed viaresult.error.name === "VcsApplyError"and now hits:Fix: narrow with
"name" in result.error && result.error.name === "VcsApplyError"before reading. Behavior unchanged —InvalidRequestErrorcontinues to fall through to the toast path, same as any other non-VcsApplyError.Test plan
bun run typecheck(full monorepo) — greenbun run buildinpackages/sdk/jsafter reverting the patched line to the buggy upstream form — confirms post-gen patch reapplies after a realcreateClientwipe + regenbun run test test/cli/run/stream.transport.test.ts— 21/21 pass