Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(nuxt): type auto-imported $fetch with nitro's $Fetch - #35704

#35704
Merged
danielroe merged 3 commits into
nuxt:mainnuxt/nuxt:mainfrom
KealanAU:fix/dollar-fetch-type-templateKealanAU/nuxt:fix/dollar-fetch-type-templateCopy head branch name to clipboard
Jul 19, 2026
Merged

fix(nuxt): type auto-imported $fetch with nitro's $Fetch#35704
danielroe merged 3 commits into
nuxt:mainnuxt/nuxt:mainfrom
KealanAU:fix/dollar-fetch-type-templateKealanAU/nuxt:fix/dollar-fetch-type-templateCopy head branch name to clipboard

Conversation

@KealanAU

Copy link
Copy Markdown
Contributor

Since #35582, the auto-imported $fetch is typed by the fetch.d.ts template as ofetch's plain $fetch, so every call returns Promise<any> with no typed-route inference. This types it as nitro's route-aware $Fetch, matching the runtime cast in #app/composables/fetch.

While investigating #22488 I found the remaining blocker is upstream: nitro's generated nitro-imports.d.ts emits import paths like .../node_modules/nitro/h3 (package dir joined with the exports subpath), which doesn't exist on disk. TS can't resolve it and skipLibCheck hides the error, so defineEventHandler becomes any and poisons all InternalApi route types. With that patched locally plus this fix, $fetch(/api/posts/${id}) correctly infers Promise<number | string>.

🔗 Linked issue: #22488

@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Jul 19, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing KealanAU:fix/dollar-fetch-type-template (6465867) with main (1dfe8e5)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@KealanAU

KealanAU commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

This fixes the Nuxt's auto-imported $fetch was typed as ofetch's $fetch, causing it to lose Nitro's route-aware typing and fall back to Promise<any>. Though it is now Promise<unknown> due to upstream Nitro where route return types from InternalApi are not currently resolved through TypedInternalResponse (tracked upstream in Nitro).
nitrojs/nitro#2758

Maybe not worth merging till then?

CleanShot 2026-07-19 at 19 30 04@2x

@KealanAU
KealanAU marked this pull request as ready for review July 19, 2026 17:34
@KealanAU
KealanAU requested a review from danielroe as a code owner July 19, 2026 17:34
@coderabbitai

This comment has been minimized.

Comment thread packages/nuxt/src/core/templates.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35704

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35704

nuxt

npm i https://pkg.pr.new/nuxt@35704

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35704

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35704

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35704

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35704

commit: 6465867

@danielroe
danielroe merged commit ba27379 into nuxt:main Jul 19, 2026
29 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
5 tasks
danielroe pushed a commit that referenced this pull request Jul 20, 2026
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
danielroe pushed a commit that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.