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

RequestContext Type Union forces type coercion #281

Closed
FelixMarcus opened this issue Feb 6, 2025 · 4 comments
Closed

RequestContext Type Union forces type coercion #281

FelixMarcus opened this issue Feb 6, 2025 · 4 comments

Comments

@FelixMarcus
Copy link

FelixMarcus commented Feb 6, 2025

Node v22.13.1
Typescript v4.9.5
lamda-api v1.1.1

Upgraded to lambda-api version 1.1.1 and began to receive this error:

Property 'authorizer' does not exist on type 'APIGatewayEventRequestContext | ALBEventRequestContext'.

The error doesn't occur on v1.1.0...

This is because the type of requestContext on Request has been changed from APIGatewayEventRequestContext to APIGatewayEventRequestContext | ALBEventRequestContext (#276). By using the type union (i.e. |), the library forces the compiler to assume it could be receiving either type, despite them having completely different properties.

To continue using the library, one would have to add in boilerplate guard clauses anywhere that the request context is used to ensure the handler hasn't received an event from a type of AWS system that it does not use and will never receive. This seems like an unnecessary burden, right?

This is a breaking change released in a patch version, and there doesn't appear to be any documentation updates alongside it.

If supporting ALB events is a desired feature, I'd recommend either making the request type generic, or creating a separate handler specifically for ALB events.

@naorpeled
Copy link
Collaborator

Hey @FelixMarcus

first of all sorry for this, I'll revert the changes and release a patch.

@naorpeled
Copy link
Collaborator

The revert is released in v1.1.2

@naorpeled
Copy link
Collaborator

Hey @FelixMarcus,
I've been working on a re-work of our type defs,
wdyt about the following usage?

#284

@FelixMarcus
Copy link
Author

Thanks @naorpeled! Appreciate the quick response :D

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

No branches or pull requests

2 participants