Skip to content

Commit

Permalink
Update TypeScript types to match actual request object passed to hand…
Browse files Browse the repository at this point in the history
…lers

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.
  • Loading branch information
airhorns committed Jul 3, 2020
1 parent 61276c6 commit 338efc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare module 'fastify' {
export type WebsocketHandler = (
this: FastifyInstance<Server, IncomingMessage, ServerResponse>,
connection: SocketStream,
request: FastifyRequest,
request: IncomingMessage,
params?: { [key: string]: any }
) => void | Promise<any>;
}
Expand Down
6 changes: 3 additions & 3 deletions test/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { Server } from 'ws';

const handler: WebsocketHandler = (
connection: SocketStream,
req: FastifyRequest,
req: IncomingMessage,
params
) => {
expectType<SocketStream>(connection);
expectType<Server>(app.websocketServer);
expectType<FastifyRequest<HttpServer, IncomingMessage, RequestGenericInterface>>(req)
expectType<IncomingMessage>(req)
expectType<{ [key: string]: any } | undefined>(params);
};

const handle = (connection: SocketStream): void => {
expectType<SocketStream>(connection)
}
}

const app: FastifyInstance = fastify();
app.register(wsPlugin);
Expand Down

0 comments on commit 338efc5

Please sign in to comment.