-
-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure it has not already been reported
Fastify version
3.15.1
Node.js version
14.5.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
The WebsocketRouteOptions
doesn't accept generics, so WebsocketHandler
is left with the defaults, not with the appropriate types.
Steps to Reproduce
import fastify from "fastify"
import fastifyWs from "fastify-websocket"
const fastify = fastify()
fastify.register(fastifyWs)
Let's say we have this interface declared:
interface AuthenticatedEndpoint extends RequestGenericInterface {
Body: {
auth: string
}
}
When using it with app.route
:
fastify.route<AuthenticatedEndpoint>({
method: 'GET',
url: '/ws',
wsHandler(conn, req) {
req.body // typed as `unknown`
req.body.auth // TypeError
}
})
Expected Behavior
(assuming we have the same starting code as we had in Steps to Reproduce)
fastify.route<AuthenticatedEndpoint>({
method: 'GET',
url: '/ws',
wsHandler(conn, req) {
req.body // typed as { auth: string }
req.body.auth // string
}
})
calvo-jpcalvo-jp
Metadata
Metadata
Assignees
Labels
No labels