Skip to content

Commit d441ad0

Browse files
authored
Fixes types and adds typescript tests to CI (#101)
* Removes RawServiceBase generic from Request/Reply * Use upstream's definitions for preHandler * Use upstreams type's for testing typescript * Adds typescript test into npm test
1 parent 77295b8 commit d441ad0

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

index.d.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/// <reference types="node" />
22

33
import {
4-
FastifyRequest,
5-
RawServerBase,
64
FastifyPlugin,
7-
FastifyError,
8-
FastifyReply
5+
preHandlerHookHandler
96
} from "fastify";
107

118
export interface FastifyHttpProxyOptions {
@@ -14,16 +11,8 @@ export interface FastifyHttpProxyOptions {
1411
rewritePrefix?: string;
1512
http2?: boolean;
1613
proxyPayloads?: boolean;
17-
preHandler?: (
18-
request: FastifyRequest<RawServerBase>,
19-
reply: FastifyReply<RawServerBase>,
20-
next: (err?: FastifyError | undefined) => void
21-
) => void;
22-
beforeHandler?: (
23-
request: FastifyRequest<RawServerBase>,
24-
reply: FastifyReply<RawServerBase>,
25-
next: (err?: FastifyError | undefined) => void
26-
) => void;
14+
preHandler?: preHandlerHookHandler;
15+
beforeHandler?: preHandlerHookHandler;
2716
config?: Object;
2817
replyOptions?: Object;
2918
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "proxy http requests, for Fastify",
55
"main": "index.js",
66
"scripts": {
7-
"test": "standard | snazzy && tap test/*.js",
7+
"test": "standard | snazzy && tap test/*.js && npm run typescript",
88
"lint:typescript": "standard --fix --parser @typescript-eslint/parser --plugin typescript test/types/*.ts",
99
"typescript": "tsd"
1010
},

test/index.test-d.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import fastify from "fastify";
1+
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from "fastify";
22
import fastifyHttpProxy from "..";
33
import { expectType } from "tsd";
4-
import { IncomingMessage, ServerResponse } from "http";
5-
import { Http2ServerRequest, Http2ServerResponse } from "http2";
64

75
const app = fastify();
86

@@ -18,11 +16,11 @@ app.register(fastifyHttpProxy, {
1816
config: { key: 1 },
1917
replyOptions: { opt: "a" },
2018
preHandler: (request, reply) => {
21-
expectType<IncomingMessage | Http2ServerRequest>(request.raw);
22-
expectType<ServerResponse | Http2ServerResponse>(reply.raw);
19+
expectType<RawRequestDefaultExpression>(request.raw);
20+
expectType<RawReplyDefaultExpression>(reply.raw);
2321
},
2422
beforeHandler: (request, reply) => {
25-
expectType<IncomingMessage | Http2ServerRequest>(request.raw);
26-
expectType<ServerResponse | Http2ServerResponse>(reply.raw);
23+
expectType<RawRequestDefaultExpression>(request.raw);
24+
expectType<RawReplyDefaultExpression>(reply.raw);
2725
}
2826
});

0 commit comments

Comments
 (0)