Skip to content

improv(parser): export InferOutput from public types entry point#5175

Merged
svozza merged 2 commits intoaws-powertools:mainfrom
yashar-new10:feat/parser-export-infer-output-type
Apr 10, 2026
Merged

improv(parser): export InferOutput from public types entry point#5175
svozza merged 2 commits intoaws-powertools:mainfrom
yashar-new10:feat/parser-export-infer-output-type

Conversation

@yashar-new10
Copy link
Copy Markdown
Contributor

Summary

Exports InferOutput from the public @aws-lambda-powertools/parser/types entry point.

Changes

TypeScript enforces that all types appearing in a function's inferred return type must be nameable via public package exports (see TS2742 / TS2883 — the latter is a variant that also reports the source module path). This check becomes harder to avoid in TypeScript 6 because the compiler is stricter about declaration emit portability.

When using the parser middleware with safeParse: true, the return type of the wrapping function includes InferOutput<TSchema>. Because InferOutput was only exported from the internal path lib/esm/types/parser.js and not from any public entry point, TypeScript 6 could not generate a valid declaration file and raised:

error TS2883: The inferred type of 'X' 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.

Consumers hitting this error were forced to add explicit type casts or annotations as a workaround.

Fix

Add InferOutput to the existing re-exports in packages/parser/src/types/index.ts. This is a one-line, type-only change with no runtime impact. Once InferOutput is available at @aws-lambda-powertools/parser/types, TypeScript can reference it in generated .d.ts files automatically and the error is resolved without any changes required on the consumer side.

Testing

Verified locally by:

  1. Manually adding InferOutput to the built lib/esm/types/index.d.ts
  2. Confirming that TS2883 is resolved without any type annotations or casts in consumer code
  3. Confirming that removing the manual edit brings the error back

Issue number: closes #5174


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 9, 2026

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added the size/XS PR between 0-9 LOC label Apr 9, 2026
@dreamorosi dreamorosi changed the title feat(parser): export InferOutput from public types entry point improv(parser): export InferOutput from public types entry point Apr 10, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added size/XS PR between 0-9 LOC and removed size/XS PR between 0-9 LOC labels Apr 10, 2026
@sonarqubecloud
Copy link
Copy Markdown

@svozza svozza merged commit 16c6de6 into aws-powertools:main Apr 10, 2026
48 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 10, 2026

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@svozza
Copy link
Copy Markdown
Contributor

svozza commented Apr 10, 2026

Thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS PR between 0-9 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: InferOutput not exported from public types entry point, causing TS2883 with TypeScript 6

2 participants