@@ -507,3 +507,98 @@ const testErrorHandlingMiddleware: ErrorHandlingMiddleware = async (
507507
508508 next ( ) ;
509509} ;
510+
511+ const testDefaultTypes = ( ) => {
512+ api . get ( '/simple' , ( req , res ) => {
513+ expectType < Request > ( req ) ;
514+ expectType < Response > ( res ) ;
515+ expectType < APIGatewayContext > ( req . requestContext ) ;
516+ expectType < Record < string , string | undefined > > ( req . query ) ;
517+ expectType < Record < string , string | undefined > > ( req . params ) ;
518+ expectType < any > ( req . body ) ;
519+ res . json ( { message : 'ok' } ) ;
520+ } ) ;
521+
522+ const simpleMiddleware : Middleware = ( req , res , next ) => {
523+ expectType < Request > ( req ) ;
524+ expectType < Response > ( res ) ;
525+ expectType < APIGatewayContext > ( req . requestContext ) ;
526+ next ( ) ;
527+ } ;
528+
529+ const simpleErrorHandler : ErrorHandlingMiddleware = (
530+ error ,
531+ req ,
532+ res ,
533+ next
534+ ) => {
535+ expectType < Request > ( req ) ;
536+ expectType < Response > ( res ) ;
537+ expectType < APIGatewayContext > ( req . requestContext ) ;
538+ res . status ( 500 ) . json ( { error : error . message } ) ;
539+ } ;
540+
541+ api . post ( '/simple-chain' , simpleMiddleware , ( req , res ) => {
542+ expectType < Request > ( req ) ;
543+ expectType < Response > ( res ) ;
544+ res . json ( { status : 'ok' } ) ;
545+ } ) ;
546+
547+ api . use ( ( req , res , next ) => {
548+ expectType < Request > ( req ) ;
549+ expectType < Response > ( res ) ;
550+ next ( ) ;
551+ } ) ;
552+
553+ api . use ( '/path' , ( req , res , next ) => {
554+ expectType < Request > ( req ) ;
555+ expectType < Response > ( res ) ;
556+ next ( ) ;
557+ } ) ;
558+
559+ api . finally ( ( req , res ) => {
560+ expectType < Request > ( req ) ;
561+ expectType < Response > ( res ) ;
562+ } ) ;
563+
564+ const runResult = api . run ( { } as APIGatewayProxyEvent , { } as Context ) ;
565+ expectType < Promise < any > > ( runResult ) ;
566+
567+ api . run ( { } as APIGatewayProxyEvent , { } as Context , ( err , res ) => {
568+ expectType < Error > ( err ) ;
569+ expectType < any > ( res ) ;
570+ } ) ;
571+
572+ const albApi = new API ( ) ;
573+ albApi . get ( '/alb-default' , ( req , res ) => {
574+ if ( isAlbContext ( req . requestContext ) ) {
575+ expectType < ALBContext > ( req . requestContext ) ;
576+ expectType < { targetGroupArn : string } > ( req . requestContext . elb ) ;
577+ expectType < Record < string , string | undefined > > ( req . query ) ;
578+ expectType < Record < string , string | undefined > > ( req . params ) ;
579+ expectType < any > ( req . body ) ;
580+ res . json ( { message : 'ALB response' } ) ;
581+ }
582+ } ) ;
583+
584+ const albResult = albApi . run ( { } as ALBEvent , { } as Context ) ;
585+ expectType < Promise < any > > ( albResult ) ;
586+
587+ 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' } ) ;
596+ }
597+ } ) ;
598+
599+ const apiGwV2Result = apiGwV2Api . run (
600+ { } as APIGatewayProxyEventV2 ,
601+ { } as Context
602+ ) ;
603+ expectType < Promise < any > > ( apiGwV2Result ) ;
604+ } ;
0 commit comments