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

Argument of type 'ScheduledHandler' is not assignable to parameter of type 'MiddyInputHandler<EventBridgeEvent<"Scheduled Event" #1239

Open
garysassano opened this issue Sep 3, 2024 · 1 comment · May be fixed by #1257

Comments

@garysassano
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
How to reproduce the behaviour:

index.ts

import { Logger } from "@aws-lambda-powertools/logger";
import { injectLambdaContext } from "@aws-lambda-powertools/logger/middleware";
import { ScheduledHandler } from "aws-lambda";
import middy from "@middy/core";
import httpErrorHandler from "@middy/http-error-handler";

const logger = new Logger();

const lambdaHandler: ScheduledHandler = async () => {
  const response = {
    statusCode: 200,
    body: "Hello from Lambda!",
  };

  console.log(response);
};

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

Expected behaviour
No error should be thrown, instead you get this:

Argument of type 'ScheduledHandler' is not assignable to parameter of type 'MiddyInputHandler<EventBridgeEvent<"Scheduled Event", any>, void, Context>'.
  Types of parameters 'callback' and 'opts' are incompatible.
    Type 'MiddyHandlerObject' is not assignable to type 'Callback<void>'.
      Type 'MiddyHandlerObject' provides no match for the signature '(error?: string | Error | null | undefined, result?: void | undefined): void'.

Environment (please complete the following information):

  • Node.js: 20.17.0
  • Middy: 5.4.7
  • AWS SDK: 3.644.0

Additional context

You can fix the issue by avoiding to use the .handler(), like this:

export const handler = middy(lambdaHandler)
  .use(injectLambdaContext(logger, { logEvent: true }))
  .use(httpErrorHandler())
@willfarrell
Copy link
Member

A PR to the v6 branch is welcome for this.

@willfarrell willfarrell added this to the v6 milestone Oct 16, 2024
R11baka added a commit to R11baka/middy that referenced this issue Nov 13, 2024
@R11baka R11baka linked a pull request Nov 13, 2024 that will close this issue
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.

2 participants