Skip to content

FEATURE-3879: added support for typescript isolatedDeclarations#3880

Open
tompuric wants to merge 7 commits into
hey-api:mainfrom
tompuric:support-typescript-isolated-declarations-3879
Open

FEATURE-3879: added support for typescript isolatedDeclarations#3880
tompuric wants to merge 7 commits into
hey-api:mainfrom
tompuric:support-typescript-isolated-declarations-3879

Conversation

@tompuric
Copy link
Copy Markdown

No description provided.

@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 May 14, 2026

@tpuric 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:L This PR changes 100-499 lines, ignoring generated files. feature 🚀 Feature request. labels May 14, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

⚠️ No Changeset found

Latest commit: bf935da

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

Important

The SDK plugin's new .returns(...) clause is appended unconditionally — for the Nuxt client this emits RequestResult<Responses, Errors, ThrowOnError>, but client-nuxt's RequestResult is parameterized as <TComposable, ResT, TError>. Regenerating any Nuxt SDK after this change will produce an annotation that doesn't match the runtime call's generics. Worth gating the new .returns(...) behind !isNuxtClient (or threading a Nuxt-specific shape through it) before merge.

TL;DR — Adds explicit return-type and field-type annotations across the core bundle templates and the SDK v1 emitter so generated output satisfies isolatedDeclarations, and enables declaration + isolatedDeclarations in several example tsconfig.json files to lock the contract in.

Key changes

  • Annotate client bundle helperscreateQuerySerializer, setAuthParams, getUrl, path/object/primitive serializers, getValidRequestBody, and queryKeyJsonReplacer get explicit return types across client-angular, client-axios, client-core, client-fetch, client-ky, client-next, client-nuxt, and client-ofetch bundle templates.
  • Type the generated client const and SDK operationsclient-core/client.ts now imports a Client type symbol and annotates export const client: Client = createClient(...); the SDK v1 emitter (sdk/v1/node.ts, sdk/v1/plugin.ts) registers RequestResult as an external symbol and appends a .returns(client.RequestResult<Responses, Errors, ThrowOnError, [responseStyle?]>) clause to every operation function.
  • Type a registry static fieldenrichRootClass adds an explicit .type($.type(symbolRegistry).generic(symbol)) to the static readonly field so the class declaration is portable without inference.
  • Enable isolatedDeclarations in examplestsconfig.json in axios, fetch, ky, nestjs, next, openai (and others) adds "declaration": true, "isolatedDeclarations": true.
  • Annotate example app code — example App.tsx, layout.tsx, page.tsx, tailwind.config.ts, pets.controller.ts, store.controller.ts, and openapi-ts.config.ts files get explicit return types (React.ReactNode, Promise<UserConfig>, etc.).

Summary | 150 files | 1 commit | base: mainsupport-typescript-isolated-declarations-3879


Nuxt SDK return type uses the wrong generic shape

Before: implementFn produced operations with inferred return types, which TS was free to resolve through the Nuxt-specific RequestResult<TComposable, ResT, TError>.
After: .returns(client.RequestResult) is appended outside the $if(isNuxtClient, ...) branch with <Responses, Errors, ThrowOnError> generics — the positional argument shape that matches the non-Nuxt clients but not Nuxt.

packages/openapi-ts/src/plugins/@hey-api/client-nuxt/bundle/types.ts:92 declares RequestResult<TComposable extends Composable = '$fetch', ResT = unknown, TError = unknown>. The new emitter will pass an SDK's *Responses type as TComposable, which is structurally meaningless and will fail to extend Composable. The fix is to skip .returns(...) for Nuxt or to emit a different shape there — the existing $if(isNuxtClient, ...) block at the top of implementFn is the natural place.

sdk/v1/node.ts · client-nuxt/bundle/types.ts


Unrelated tsconfig.json flips in openapi-ts-next

Before: "allowJs": true in the Next example.
After: "allowJs": false alongside the new declaration / isolatedDeclarations flags.

allowJs has nothing to do with isolated declarations; flipping it scopes a behavior change that isn't motivated by the PR title. The example's postcss.config.mjs is the only .mjs and likely isn't in the program, so it probably still builds, but the flip is worth either reverting or calling out explicitly in the PR description.

examples/openapi-ts-next/tsconfig.json


Mechanical generated-file churn dominates the diff

Roughly 130 of the 150 files are regenerated .gen.ts outputs across 16 example projects — they reflect the source-side annotations and look internally consistent. The substantive review surface is the ~15 source files under packages/openapi-ts/src/plugins/@hey-api/. Worth running pnpm test to confirm the snapshot test suites under packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/** and other client snapshots are also regenerated — none of them appear in this diff, and they will diverge once this code lands.

client-core/client.ts · client-core/bundle/utils.ts · sdk/v1/plugin.ts

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Claude Opus𝕏

Comment on lines +315 to +336
.returns(
$.type(plugin.external('client.RequestResult'))
.generic(
plugin.querySymbol({
category: 'type',
resource: 'operation',
resourceId: operation.id,
role: 'responses',
}) ?? 'unknown',
)
.generic(
plugin.querySymbol({
category: 'type',
resource: 'operation',
resourceId: operation.id,
role: 'errors',
}) ?? 'unknown',
)
.generic('ThrowOnError')
.$if(plugin.config.responseStyle === 'data', (t) =>
t.generic($.type.literal(plugin.config.responseStyle)),
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This .returns(...) is applied unconditionally, but the $if(isNuxtClient, ...) block above already adds Nuxt-specific generics (TComposable, TDefault) that don't fit RequestResult<Responses, Errors, ThrowOnError>. Nuxt's own RequestResult is <TComposable, ResT, TError> (see client-nuxt/bundle/types.ts:92), so the emitted annotation will pass a *Responses type where TComposable extends Composable is expected. Gate this clause behind !isNuxtClient (or emit the Nuxt shape there).

Copy link
Copy Markdown
Author

@tompuric tompuric May 14, 2026

Choose a reason for hiding this comment

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

I'm mostly concerned about fetch as that's our client so i'm not sure how Nuxt plays into this. The generated examples are essentially a demo of the potential output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The SDK emitter is shared across all clients though — implementFn runs for every client including client-nuxt, so the unconditional .returns(client.RequestResult<Responses, Errors, ThrowOnError>) will be emitted into Nuxt-generated SDKs and won't match RequestResult<TComposable, ResT, TError> from client-nuxt/bundle/types.ts:92. The existing $if(isNuxtClient, ...) block at line 287 is the natural seam: either skip .returns(...) when isNuxtClient, or emit <TComposable, Responses, Errors> in that branch. Even if fetch is the priority, leaving Nuxt's emitted output broken under isolatedDeclarations is the kind of regression that surfaces later as a snapshot/build break.

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowJs": false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Flipping allowJs from true to false is unrelated to isolated declarations and should be either reverted or called out in the PR description. The example's postcss.config.mjs is the only loose script and isn't in the program, but the change still reads as scope creep.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This was switched because openapi-ts build failure occurred with the reason being that allowJs: true being incompatible with isolatedDeclarations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense — allowJs + isolatedDeclarations is incompatible without --declaration constraints on the JS surface, so flipping it here is justified. Worth a one-line note in the PR description so reviewers don't read it as scope creep.

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

bodySerializer?: BodySerializer | null;
serializedBody?: unknown;
}) {
}): unknown {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getValidRequestBody's annotated return type unknown is correct (all branches return unknown | null | undefined) but it does erase the input narrowing callers previously got via inference. If any caller relies on a narrower inferred type, they'll need their own annotation — worth a quick grep before merging.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yep not ideal, feel free to provide suggestions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concretely: the function already returns unknown | null | undefined, so the explicit unknown is correct and no caller can narrow further from the signature alone — unknown widens what inference gave you, but only callers that did if (body) { ... } style refinement keep their narrowing through control flow. A grep for getValidRequestBody( in the client bundles shows every call site immediately passes the result to fetch/axios/etc., which accept unknown-ish bodies, so no follow-up annotation is required. If you wanted to preserve precision, a generic <T>(options: { body?: T; ... }): T | null | undefined would work, but it's bloat for zero practical benefit here.

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

@mrlubos
Copy link
Copy Markdown
Member

mrlubos commented May 14, 2026

@pullfrog reply to the comments

@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog Bot commented May 14, 2026

Replied to all three author responses on the prior review: acknowledged the allowJs flip as justified by isolatedDeclarations (suggested a PR-description note), explained the getValidRequestBody: unknown widening has no real caller impact (with a generic alternative if precision is desired), and pushed back on the Nuxt .returns(...) since the SDK emitter is shared and the unconditional clause still emits a broken shape into Nuxt-generated SDKs. No code changes were requested or made.

Task list (4/4 completed)
  • Checkout PR branch
  • Fetch comments on issue/PR 3880
  • Investigate context for each thread
  • Reply to each review thread

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

@mrlubos
Copy link
Copy Markdown
Member

mrlubos commented May 14, 2026

@tompuric will you update the snapshots?

@tompuric
Copy link
Copy Markdown
Author

@tompuric will you update the snapshots?

Hey @mrlubos , I'm not familiar with contributing to the repo so I'll see how I can get the PR in shape 👍 Feel free to point me around or take control.

@mrlubos
Copy link
Copy Markdown
Member

mrlubos commented May 14, 2026

@tompuric should need just pnpm test:update and push committed changes

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.50%. Comparing base (6353658) to head (bf935da).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3880      +/-   ##
==========================================
- Coverage   39.58%   39.50%   -0.08%     
==========================================
  Files         532      533       +1     
  Lines       19581    19656      +75     
  Branches     5835     5852      +17     
==========================================
+ Hits         7751     7766      +15     
- Misses       9582     9639      +57     
- Partials     2248     2251       +3     
Flag Coverage Δ
unittests 39.50% <ø> (-0.08%) ⬇️

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.

@mrlubos
Copy link
Copy Markdown
Member

mrlubos commented May 14, 2026

@tompuric now it gives you actual type errors. Does that not happen on your end when you said the current implementation works for you?

@tompuric
Copy link
Copy Markdown
Author

tompuric commented May 14, 2026

When I say works for me, I mean when i yarn patch my changes into our repo it's 👍

  • as for the pipelines within openapi-ts, that needs to be worked out as i'm touching plugins that i'm not using. Hence a demo PR I wanted to showcase for what I'm suggesting should be solved. Hope that makes sense

Edit: i'll see what I can do to get the PR ready here, but might not get to it until next week

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

@hey-api/codegen-core

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

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

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

@hey-api/nuxt

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

@hey-api/openapi-ts

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

@hey-api/shared

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

@hey-api/spec-types

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

@hey-api/types

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

@hey-api/vite-plugin

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

commit: bf935da

@@ -307,6 +317,31 @@ function implementFn<T extends ReturnType<typeof $.func | typeof $.method>>(args
),
)
.params(...opParameters.parameters)
.$if(!isNuxtClient && !hasServerSentEvents, (m) =>
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This needs to be validated. Had trouble getting these two integrated.

Question: should these paths be covered?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've resolved this and have covered all areas in a cleaner/easier-to-read approach

@tompuric
Copy link
Copy Markdown
Author

Hey @mrlubos , the PR is now in a ready state 🥳

I'm not sure how to improve the code coverage here for these changes so let me know if that's required.

Let me know how else I can assist with this, thanks 🙏

@tompuric tompuric force-pushed the support-typescript-isolated-declarations-3879 branch from b63675a to bf935da Compare May 14, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 🚀 Feature request. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants