Skip to content

Commit 0838d43

Browse files
authored
Update TypeScript types to match actual request object passed to handlers (#64)
In the README it states (and in my experience also) the handler doesn't get a full on `FastifyRequest` object. It gets an `http.IncomingMessage` instead! This makes the TypeScript types reflect that.
1 parent 61276c6 commit 0838d43

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare module 'fastify' {
3131
export type WebsocketHandler = (
3232
this: FastifyInstance<Server, IncomingMessage, ServerResponse>,
3333
connection: SocketStream,
34-
request: FastifyRequest,
34+
request: IncomingMessage,
3535
params?: { [key: string]: any }
3636
) => void | Promise<any>;
3737
}

test/types/index.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { Server } from 'ws';
66

77
const handler: WebsocketHandler = (
88
connection: SocketStream,
9-
req: FastifyRequest,
9+
req: IncomingMessage,
1010
params
1111
) => {
1212
expectType<SocketStream>(connection);
1313
expectType<Server>(app.websocketServer);
14-
expectType<FastifyRequest<HttpServer, IncomingMessage, RequestGenericInterface>>(req)
14+
expectType<IncomingMessage>(req)
1515
expectType<{ [key: string]: any } | undefined>(params);
1616
};
1717

1818
const handle = (connection: SocketStream): void => {
1919
expectType<SocketStream>(connection)
20-
}
20+
}
2121

2222
const app: FastifyInstance = fastify();
2323
app.register(wsPlugin);

0 commit comments

Comments
 (0)