Skip to content

Commit

Permalink
Use req and res type alias to simplify code (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElianCordoba authored and delvedor committed Jan 18, 2020
1 parent 6d204f9 commit 6a3bfaf
Showing 1 changed file with 12 additions and 9 deletions.
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

0 comments on commit 6a3bfaf

Please sign in to comment.