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);