fix: use Promise<Response> for async kit handler return types#2966
Merged
jasonlyu123 merged 5 commits intosveltejs:masterfrom Mar 7, 2026
Merged
fix: use Promise<Response> for async kit handler return types#2966jasonlyu123 merged 5 commits intosveltejs:masterfrom
jasonlyu123 merged 5 commits intosveltejs:masterfrom
Conversation
When svelte-check adds type annotations to SvelteKit route handlers (GET, POST, etc.), it was using `Response | Promise<Response>` as the return type for all functions regardless of whether they were async. TypeScript requires async functions to return `Promise<T>`, not `T | Promise<T>` (TS1064). This caused false positives in `--incremental` mode where tsc runs on the generated files directly. The fix checks if the function has an async modifier and, if so, extracts just the `Promise<Response>` part of the return type union. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: f003bca The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updated async kit handler return types to use Promise<Response>.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
We need this fix to be able to use the |
jasonlyu123
reviewed
Mar 5, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jasonlyu123
approved these changes
Mar 5, 2026
Merged
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
When svelte-check adds type annotations to SvelteKit route handlers (GET, POST, PUT, PATCH, DELETE, etc.), it uses
Response | Promise<Response>as the return type for all functions. However, TypeScript requires async functions to returnPromise<T>, notT | Promise<T>(TS1064).This caused false positive errors in
--incrementalmode, where tsc runs directly on the generated overlay files. In non-incremental mode these errors were silently filtered out by the TypeScript plugin'sinGenerateddiagnostic filtering, but in incremental mode tsc reports them directly.The bug
Changes
packages/svelte2tsx/src/helpers/sveltekit.ts: InaddTypeToFunction, check if the function has anasyncmodifier. If so, extract just thePromise<T>part from the return type union instead of using the fullT | Promise<T>.packages/svelte2tsx/test/helpers/index.ts: Updated the async GET test to expectPromise<Response>and added a new test for non-async GET to verify it still getsResponse | Promise<Response>.packages/svelte-check/test-success/: Added an async+server.tsfixture with GET and POST handlers plus the necessaryRequestEventtype to the sanity test suite.Test plan
upserts GET async functionfails without fix, passes with fixupserts GET non-async functionpasses (non-async still usesResponse | Promise<Response>)