Skip to content

Bug: Type error when using request context in event handler route method #5051

@svozza

Description

@svozza

Expected Behavior

When you define a route using the app.route with a handler that uses the reqCtx object it should be of type of RequestContext or TypedRequestContext.

Current Behavior

Currently when you try to access the context object you get a typescript error: Parameter 'reqCtx' implicitly has an 'any' type.

Code snippet

const app = new Router();
app.route(({req}) => { // <- type error
      return req;
    }, {
      path: '/test',
      method: [HttpVerbs.GET, HttpVerbs.POST],
    });

Steps to Reproduce

Create a simple handler like the code example above that interacts with the request context object in any way and you will see the error.

Possible Solution

The issue is that we are missing a method overload on the route method that the other HTTP handlers have that tell the compiler that reqCtx is of type RequestContext when there is no validation options object and TypedRequestContext when it is present.

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

24.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions