BlitzServerMiddleware types are incorrect
tmcw opened this issue · comments
What is the problem?
The types for BlitzServerMiddleware specify the response object as simply a ServerResponse
blitz/packages/blitz/src/index-server.ts
Lines 24 to 28 in 0a8d4bf
But it is not: as the docs lay out, the response object has additional methods, including .send()
. So correct code will get incorrectly flagged by TypeScript.
Paste all your error logs here:
PASTE_HERE (leave the ``` marks)
Paste all relevant code snippets here:
app/blitz-server.ts:39:15 - error TS2551: Property 'send' does not exist on type 'ServerResponse<IncomingMessage>'. Did you mean 'end'?
39 res.send({ error: "Bad request", issues: e.issues });
~~~~
What are detailed steps to reproduce this?
- Create a BlitzServerMiddleware that uses
res.send()
Run blitz -v
and paste the output here:
placemark-oss on typescript-5 [$!] via v18.12.0
➜ y blitz -v
yarn run v1.22.19
$ /Users/tmcw/p/placemark-oss/node_modules/.bin/blitz -v
Blitz version: 2.0.2 (local)
macOS | darwin-arm64 | Node: v18.12.0
Package manager: npm
System:
OS: macOS 14.3
CPU: (8) arm64 Apple M2
Memory: 2.32 GB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.12.0 - /var/folders/cs/3sq9lh_j5hjgf9cvbmc8dqkr0000gn/T/yarn--1706981494183-0.4718846359980571/node
Yarn: 1.22.19 - /var/folders/cs/3sq9lh_j5hjgf9cvbmc8dqkr0000gn/T/yarn--1706981494183-0.4718846359980571/yarn
npm: 8.19.2 - ~/.volta/tools/image/node/18.12.0/bin/npm
npmPackages:
@blitzjs/auth: 2.0.2 => 2.0.2
@blitzjs/next: 2.0.2 => 2.0.2
@blitzjs/rpc: 2.0.2 => 2.0.2
@prisma/client: ^5 => 5.9.1
blitz: 2.0.2 => 2.0.2
next: 13.5.6 => 13.5.6
prisma: ^5 => 5.9.1
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: 5 => 5.3.3
Please include below any other applicable logs and screenshots that show your problem:
No response
Thanks for the issue. Will be taking a look.
@tmcw here is a userland quick for now, while we check for a way to make it the default behaviour
+import type {BlitzNextApiResponse} from "@blitzjs/next"
+import type {RequestMiddleware} from "blitz"
+import type {NextApiRequest} from "next"
-BlitzServerMiddleware((req, res, next) => {
+BlitzServerMiddleware<RequestMiddleware<NextApiRequest, BlitzNextApiResponse>>((req, res, next) => {