Skip to content
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

Restrict types to APIGatewayProxyResultV2 or APIGatewayProxyResult #1175

Closed
jlarmstrongiv opened this issue Feb 12, 2024 · 3 comments · Fixed by #1212
Closed

Restrict types to APIGatewayProxyResultV2 or APIGatewayProxyResult #1175

jlarmstrongiv opened this issue Feb 12, 2024 · 3 comments · Fixed by #1212

Comments

@jlarmstrongiv
Copy link

Describe the bug

The TypeScript types indicate properties exist in Middy handlers that do not.

To Reproduce
How to reproduce the behaviour:

  1. With a function url that uses the payload version format v2 with middy

Expected behaviour
If I specify APIGatewayProxyEventV2 and APIGatewayProxyResultV2 in export const middy = middyCore<APIGatewayProxyEventV2, APIGatewayProxyResultV2>(), then the handlers should only use the v2 types.

Environment (please complete the following information):

  • Node.js: v20.11.0
  • Middy: 5.2.4
  • AWS SDK 2.1551.0

Additional context
The actual types include the old event formats

MiddyfiedHandler<APIGatewayProxyEventV2 & Omit<APIGatewayProxyEvent, "body"> & { body: JsonValue; } & APIGatewayProxyEvent & ... 4 more ... & { ...; }, APIGatewayProxyResultV2, Error, Context, {}>.handler: <unknown>(handler: MiddyInputHandler<APIGatewayProxyEventV2 & Omit<APIGatewayProxyEvent, "body"> & {
    body: JsonValue;
} & APIGatewayProxyEvent & ... 4 more ... & {
    ...;
}, APIGatewayProxyResultV2, Context>) => MiddyfiedHandler<...>
@b3nk3
Copy link

b3nk3 commented Feb 15, 2024

I'm running into some errors that are very similar to this, when using the http-router and it stems from using a middleware on the handlers, as the handler changes the types, rightly so, but the typing of the routes variable is unable to pick this up...

The code works, but I kinda have to ignore the typescript on that level.

Given the number of different middlewares, and their various outputs - this is not an easy thing to fix.

TS Playground example

@naorpeled
Copy link
Contributor

Hey @willfarrell,
should I take a look at this?

@willfarrell
Copy link
Member

@naorpeled sure

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

Successfully merging a pull request may close this issue.

4 participants