Skip to content

RequestContext Type Union forces type coercion #281

Closed
@FelixMarcus

Description

@FelixMarcus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions