Skip to content

Commit 08443a0

Browse files
committed
.
1 parent 18d419f commit 08443a0

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

index.test-d.ts

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ const testErrorHandlingMiddleware: ErrorHandlingMiddleware = async (
509509
};
510510

511511
const testDefaultTypes = () => {
512-
api.get('/simple', (req, res) => {
513-
expectType<Request>(req);
512+
api.get('/simple', (req: Request<APIGatewayContext>, res: Response) => {
513+
expectType<Request<APIGatewayContext>>(req);
514514
expectType<Response>(res);
515515
expectType<APIGatewayContext>(req.requestContext);
516516
expectType<Record<string, string | undefined>>(req.query);
@@ -519,58 +519,71 @@ const testDefaultTypes = () => {
519519
res.json({ message: 'ok' });
520520
});
521521

522-
const simpleMiddleware: Middleware = (req, res, next) => {
523-
expectType<Request>(req);
522+
const simpleMiddleware: Middleware = (
523+
req: Request<APIGatewayContext>,
524+
res: Response,
525+
next: NextFunction
526+
) => {
527+
expectType<Request<APIGatewayContext>>(req);
524528
expectType<Response>(res);
525529
expectType<APIGatewayContext>(req.requestContext);
526530
next();
527531
};
528532

529533
const simpleErrorHandler: ErrorHandlingMiddleware = (
530-
error,
531-
req,
532-
res,
533-
next
534+
error: Error,
535+
req: Request<APIGatewayContext>,
536+
res: Response,
537+
next: NextFunction
534538
) => {
535-
expectType<Request>(req);
539+
expectType<Request<APIGatewayContext>>(req);
536540
expectType<Response>(res);
537541
expectType<APIGatewayContext>(req.requestContext);
538542
res.status(500).json({ error: error.message });
539543
};
540544

541-
api.post('/simple-chain', simpleMiddleware, (req, res) => {
542-
expectType<Request>(req);
543-
expectType<Response>(res);
544-
res.json({ status: 'ok' });
545-
});
545+
api.post(
546+
'/simple-chain',
547+
simpleMiddleware,
548+
(req: Request<APIGatewayContext>, res: Response) => {
549+
expectType<Request<APIGatewayContext>>(req);
550+
expectType<Response>(res);
551+
res.json({ status: 'ok' });
552+
}
553+
);
546554

547-
api.use((req, res, next) => {
548-
expectType<Request>(req);
549-
expectType<Response>(res);
550-
next();
551-
});
555+
api.use(
556+
(req: Request<APIGatewayContext>, res: Response, next: NextFunction) => {
557+
expectType<Request<APIGatewayContext>>(req);
558+
expectType<Response>(res);
559+
next();
560+
}
561+
);
552562

553-
api.use('/path', (req, res, next) => {
554-
expectType<Request>(req);
555-
expectType<Response>(res);
556-
next();
557-
});
563+
api.use(
564+
'/path',
565+
(req: Request<APIGatewayContext>, res: Response, next: NextFunction) => {
566+
expectType<Request<APIGatewayContext>>(req);
567+
expectType<Response>(res);
568+
next();
569+
}
570+
);
558571

559-
api.finally((req, res) => {
560-
expectType<Request>(req);
572+
api.finally((req: Request<APIGatewayContext>, res: Response) => {
573+
expectType<Request<APIGatewayContext>>(req);
561574
expectType<Response>(res);
562575
});
563576

564577
const runResult = api.run({} as APIGatewayProxyEvent, {} as Context);
565578
expectType<Promise<any>>(runResult);
566579

567-
api.run({} as APIGatewayProxyEvent, {} as Context, (err, res) => {
580+
api.run({} as APIGatewayProxyEvent, {} as Context, (err: Error, res: any) => {
568581
expectType<Error>(err);
569582
expectType<any>(res);
570583
});
571584

572585
const albApi = new API();
573-
albApi.get('/alb-default', (req, res) => {
586+
albApi.get('/alb-default', (req: Request<ALBContext>, res: Response) => {
574587
if (isAlbContext(req.requestContext)) {
575588
expectType<ALBContext>(req.requestContext);
576589
expectType<{ targetGroupArn: string }>(req.requestContext.elb);
@@ -585,16 +598,19 @@ const testDefaultTypes = () => {
585598
expectType<Promise<any>>(albResult);
586599

587600
const apiGwV2Api = new API();
588-
apiGwV2Api.get('/apigw-v2-default', (req, res) => {
589-
if (isApiGatewayV2Context(req.requestContext)) {
590-
expectType<APIGatewayV2Context>(req.requestContext);
591-
expectType<string>(req.requestContext.accountId);
592-
expectType<Record<string, string | undefined>>(req.query);
593-
expectType<Record<string, string | undefined>>(req.params);
594-
expectType<any>(req.body);
595-
res.json({ message: 'API Gateway V2 response' });
601+
apiGwV2Api.get(
602+
'/apigw-v2-default',
603+
(req: Request<APIGatewayV2Context>, res: Response) => {
604+
if (isApiGatewayV2Context(req.requestContext)) {
605+
expectType<APIGatewayV2Context>(req.requestContext);
606+
expectType<string>(req.requestContext.accountId);
607+
expectType<Record<string, string | undefined>>(req.query);
608+
expectType<Record<string, string | undefined>>(req.params);
609+
expectType<any>(req.body);
610+
res.json({ message: 'API Gateway V2 response' });
611+
}
596612
}
597-
});
613+
);
598614

599615
const apiGwV2Result = apiGwV2Api.run(
600616
{} as APIGatewayProxyEventV2,

0 commit comments

Comments
 (0)