Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use req and res type alias to simplify code #142

Merged
merged 1 commit into from
Jan 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions index.d.ts
Expand Up @@ -47,9 +47,12 @@ declare namespace Router {
| 'UNLOCK'
| 'UNSUBSCRIBE';

type Req<V> = V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest;
type Res<V> = V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse;

type Handler<V extends HTTPVersion> = (
req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest,
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse,
req: Req<V>,
res: Res<V>,
params: { [k: string]: string | undefined },
store: any
) => void;
Expand All @@ -64,14 +67,14 @@ declare namespace Router {
maxParamLength?: number;

defaultRoute?(
req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest,
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse
req: Req<V>,
res: Res<V>
): void;

onBadUrl?(
path: string,
req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest,
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse
req: Req<V>,
res: Res<V>
): void;

versioning? : {
Expand All @@ -81,7 +84,7 @@ declare namespace Router {
del(version: String) : void,
empty() : void
},
deriveVersion<Context>(req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest, ctx?: Context) : String,
deriveVersion<Context>(req: Req<V>, ctx?: Context) : String,
}
}

Expand Down Expand Up @@ -131,8 +134,8 @@ declare namespace Router {
off(method: HTTPMethod | HTTPMethod[], path: string): void;

lookup<Context>(
req: V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest,
res: V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse,
req: Req<V>,
res: Res<V>,
ctx?: Context
): void;

Expand Down