Skip to content

Bug: TS Compilation error when passing injectLambdaContext as a middy middleware #1258

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
varqasim opened this issue Jan 20, 2023 · 3 comments
Assignees
Labels
logger This item relates to the Logger Utility not-a-bug New and existing bug reports incorrectly submitted as bug rejected This is something we will not be working on. At least, not in the measurable future

Comments

@varqasim
Copy link

varqasim commented Jan 20, 2023

Expected Behaviour

The project would compile successfully

Current Behaviour

Using @middy/core v1.5.1 & just updated @aws-lambda-powertools/logger to v1.5.1 and I believe that adding the middy interface #1225 is causing a TS compilation error in my project. I was able to get rid of it by downgrading to v1.5.0.

The following compilation error I am presented with is

Argument of type 'MiddlewareLikeObj<unknown, unknown, Error, Context>' is not assignable to parameter of type 'MiddlewareObject<APIGatewayProxyEvent, { statusCode: number; body: string; }, Context> | MiddlewareObject<APIGatewayProxyEvent, { ...; }, Context>[]'.
  Type 'MiddlewareLikeObj<unknown, unknown, Error, Context>' is not assignable to type 'MiddlewareObject<APIGatewayProxyEvent, { statusCode: number; body: string; }, Context>'.
    Types of property 'before' are incompatible.
      Type 'MiddlewareFn<unknown, unknown, Error, Context>' is not assignable to type 'MiddlewareFunction<APIGatewayProxyEvent, { statusCode: number; body: string; }, Context>'.
        Types of parameters 'request' and 'handler' are incompatible.
          Property 'internal' is missing in type 'HandlerLambda<APIGatewayProxyEvent, { statusCode: number; body: string; }, Context>' but required in type 'Request<unknown, unknown, Error, Context>'.ts(2345)
middy.d.ts(14, 5): 'internal' is declared here.

I came to this conclusion by looking at the last line middy.d.ts(14, 5): 'internal' is declared here. which was introduced in this PR introduced #1225.

Code snippet

import { APIGatewayEvent } from 'aws-lambda';
import { Logger, injectLambdaContext } from '@aws-lambda-powertools/logger';
import middy from '@middy/core'

const lambdaHandler = async (event: APIGatewayEvent) => {
  const { sub: userId } = event.requestContext.authorizer!.claims;
}

export const handler = middy(lambdaHandler)
  .use(injectLambdaContext(logger, { logEvent: true }));

Possible Solution

No response

Steps to Reproduce

Install @middy/core v1.5.1 & and set @aws-lambda-powertools/logger to v1.5.1

AWS Lambda Powertools for TypeScript version

1.51

AWS Lambda function runtime

14.x

Packaging format used

Npm

Execution logs

No response

@varqasim varqasim added triage This item has not been triaged by a maintainer, please wait bug Something isn't working labels Jan 20, 2023
@dreamorosi
Copy link
Contributor

Hi, we don't support @middy/[email protected], could you please try with @middy/[email protected]?

If you still have issues also with that version, could you also share an example of how you're bundling your code and your configs, so that we can investigate further?

@varqasim
Copy link
Author

@dreamorosi Thank you, then this bug doesn't make sense because it actually works with the v3.6.2 version.

@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi added rejected This is something we will not be working on. At least, not in the measurable future logger This item relates to the Logger Utility and removed triage This item has not been triaged by a maintainer, please wait labels Jun 9, 2023
@dreamorosi dreamorosi self-assigned this Jun 9, 2023
@dreamorosi dreamorosi moved this from Triage to Shipped in Powertools for AWS Lambda (TypeScript) Jan 30, 2024
@dreamorosi dreamorosi added not-a-bug New and existing bug reports incorrectly submitted as bug and removed bug Something isn't working labels Jan 30, 2024
@dreamorosi dreamorosi moved this from Shipped to Closed in Powertools for AWS Lambda (TypeScript) Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logger This item relates to the Logger Utility not-a-bug New and existing bug reports incorrectly submitted as bug rejected This is something we will not be working on. At least, not in the measurable future
Projects
Development

No branches or pull requests

2 participants