Skip to content

jsonSerializer does not pass through correct event type #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
parkan opened this issue Dec 1, 2020 · 4 comments
Closed

jsonSerializer does not pass through correct event type #45

parkan opened this issue Dec 1, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@parkan
Copy link

parkan commented Dec 1, 2020

Describe the bug

Hello it's me again 🙂

jsonSerializer (and I think some of the other middlewares as well) don't respect the pattern of generically passing the event from the previous middleware described in the README so the type information about the modified event is lost, replaced with base APIGatewayEvent

To Reproduce

compose(
  errorHandler(),
  jwtAuth(...),
  jsonSerializer()
)(handler) // the handler gets APIGatewayEvent without AuthorizedEvent

Expected behavior

Type information is preserved in the chain

Additional context

This should be a simple fix, replace

export const jsonSerializer = () => (
  handler: PromiseHandler<APIGatewayEvent, JSONObject | undefined>
) => 
...

with

export const jsonSerializer = () => (
  <E extends APIGatewayProxyEvent>(handler: PromiseHandler<APIGatewayEvent, JSONObject | undefined>): PromiseHandler<E, APIGatewayProxyResult> =>
...

happy to PR this!

@parkan parkan added the bug Something isn't working label Dec 1, 2020
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.95. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@parkan
Copy link
Author

parkan commented Dec 1, 2020

seems that this exact configuration is used in https://github.com/dbartholomae/lambda-middleware/blob/main/internal/e2e-tests/examples/helloWorld.ts#L52 but the handler doesn't actually use anything other than body on the event, I can add a test for .auth/explicit event type expectation

@dbartholomae
Copy link
Owner

Unfortunately there is a limit to how TypeScript is implemented that currently makes it impossible to have a full 100% passthrough of events. This was discussed in detail in #36. Please feel free to play around with it a bit, maybe there is a way to improve it I didn't find :)

@parkan
Copy link
Author

parkan commented Dec 1, 2020

gotcha, gonna close this for now and mess around with it a bit

@parkan parkan closed this as completed Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants