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 · 0 comments

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants