From cd6a23a7ea4b2967adcc50b54bd82ef737323e08 Mon Sep 17 00:00:00 2001 From: Fulvio Gentile Date: Sun, 29 Oct 2023 17:19:32 +0100 Subject: [PATCH] fix(http-json-body-parser): parameter typings fixes: #1116 --- packages/http-json-body-parser/index.d.ts | 2 +- packages/http-json-body-parser/index.test-d.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/http-json-body-parser/index.d.ts b/packages/http-json-body-parser/index.d.ts index 1586a4f85..2ae2e876e 100644 --- a/packages/http-json-body-parser/index.d.ts +++ b/packages/http-json-body-parser/index.d.ts @@ -14,6 +14,6 @@ export type Event = Omit & { body: JsonValue } -declare function jsonBodyParser (options?: Options): middy.MiddlewareObj +declare function jsonBodyParser (options?: Options): middy.MiddlewareObj export default jsonBodyParser diff --git a/packages/http-json-body-parser/index.test-d.ts b/packages/http-json-body-parser/index.test-d.ts index c7bca7665..84850eb0f 100644 --- a/packages/http-json-body-parser/index.test-d.ts +++ b/packages/http-json-body-parser/index.test-d.ts @@ -1,13 +1,26 @@ import middy from '@middy/core' import { expectType } from 'tsd' +import { APIGatewayEvent, Context } from 'aws-lambda' import jsonBodyParser, { Event } from '.' // use with default options let middleware = jsonBodyParser() -expectType>(middleware) +expectType>(middleware) // use with all options middleware = jsonBodyParser({ reviver: (key: string, value: any) => Boolean(value) }) -expectType>(middleware) +expectType>(middleware) + +const handler = (event: APIGatewayEvent, _context: Context) => { + console.log(event.body); +}; + +const wrapped = middy(handler).use(jsonBodyParser()); + +const event: APIGatewayEvent = {} as any; +const context: Context = {} as any; + +expectType[0]>(event); +expectType[1]>(context);