Hotfix: Temporarily disable static type checking for route handler return type #55261
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.
Why?
#51394 added static type checking for route handlers return type, so all route handlers must return
Response | Promise<Response>
.But the checker cannot detect when the function always throws, for example
because
GET
is inferred as() => void
, not as() => never
, adding| never
to the type checker can't fix it.I can't find a way to get this to work (see the "Notes" section below for more details), so this PR disables that entire type checking so route handlers like the above can pass. Hopefully this change is temporary.
How?
Remove the part where the TS plugin checks for the return type of route handlers.
Notes
Without this PR, the following still works, because the return type is made known to TypeScript:
Allowing
never
in the TS pluginwill also make the following work:
because
GET
is inferred to returnnever
. However, using regular function declaration won't work because it is inferred to returnvoid
(see microsoft/TypeScript#8767 and microsoft/TypeScript#16608). I can't figure out how to get type checking to work without requiring users to either use arrow functions or explicitly define the return type.Interested people can go to this minimal TypeScript example and try to fix.