Expected Behavior
Code using the parser middleware with safeParse: true should compile cleanly under TypeScript 6. All types that appear in the inferred return type of a consumer function must be reachable via a public package export so TypeScript can generate valid .d.ts declaration files.
Current Behavior
Compiling with TypeScript 6 raises:
error TS2883: The inferred type of 'myHandler' cannot be named without a reference to
'InferOutput' from '.../node_modules/@aws-lambda-powertools/parser/lib/esm/types/parser.js'.
This is likely not portable. A type annotation is necessary.
InferOutput is used in the parser() middleware's type signature but is only reachable at the internal path lib/esm/types/parser.js. It is not re-exported from @aws-lambda-powertools/parser/types or any other public entry point, so TypeScript cannot include a portable reference to it in generated declaration files.
Code snippet
import middy from '@middy/core';
import { parser } from '@aws-lambda-powertools/parser/middleware';
import { APIGatewayProxyEventV2Schema } from '@aws-lambda-powertools/parser/schemas';
// TS2883 is raised on this exported symbol
export const myHandler = middy()
.use(parser({ schema: APIGatewayProxyEventV2Schema, safeParse: true }))
.handler(async (event) => {
return { statusCode: 200 };
});
Steps to Reproduce
- Create a TypeScript project with
typescript@^6.0.0
- Install
@aws-lambda-powertools/parser, @middy/core, and zod
- Add the code snippet above to an exported file (declaration emit must be on, or use
tsc --noEmit)
- Run
tsc
- Observe TS2883
Possible Solution
Export InferOutput from packages/parser/src/types/index.ts so it is available at the public @aws-lambda-powertools/parser/types entry point. This is a one-line, type-only change with no runtime impact — TypeScript will then automatically use the public path in generated .d.ts files and the error resolves without any changes required on the consumer side.
I am opening a PR with this fix alongside this issue.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
24.x
Packaging format used
npm
Execution logs
Expected Behavior
Code using the
parsermiddleware withsafeParse: trueshould compile cleanly under TypeScript 6. All types that appear in the inferred return type of a consumer function must be reachable via a public package export so TypeScript can generate valid.d.tsdeclaration files.Current Behavior
Compiling with TypeScript 6 raises:
InferOutputis used in theparser()middleware's type signature but is only reachable at the internal pathlib/esm/types/parser.js. It is not re-exported from@aws-lambda-powertools/parser/typesor any other public entry point, so TypeScript cannot include a portable reference to it in generated declaration files.Code snippet
Steps to Reproduce
typescript@^6.0.0@aws-lambda-powertools/parser,@middy/core, andzodtsc --noEmit)tscPossible Solution
Export
InferOutputfrompackages/parser/src/types/index.tsso it is available at the public@aws-lambda-powertools/parser/typesentry point. This is a one-line, type-only change with no runtime impact — TypeScript will then automatically use the public path in generated.d.tsfiles and the error resolves without any changes required on the consumer side.I am opening a PR with this fix alongside this issue.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
24.x
Packaging format used
npm
Execution logs