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

TypeScript error when using S3Handler type #1182

Closed
garysassano opened this issue Feb 28, 2024 · 8 comments · Fixed by #1216 or #1217
Closed

TypeScript error when using S3Handler type #1182

garysassano opened this issue Feb 28, 2024 · 8 comments · Fixed by #1216 or #1217

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:

const lambdaHandler: S3Handler = async (event: S3Event): Promise<void> => {
  await Promise.all(event.Records.map(processRecord));
};

export const handler = middy().use(eventNormalizer()).handler(lambdaHandler);
Argument of type 'S3Handler' is not assignable to parameter of type 'MiddyInputHandler<S3Event, any, 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'.

Expected behaviour
A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • Node.js: [e.g. 20]
  • Middy: [e.g. 5.0.0]
  • AWS SDK [e.g. 3.0.0]

Additional context
Add any other context about the problem here.

@willfarrell
Copy link
Member

I think this was fix in the last release. If not, would you like to submit a PR?

@garysassano
Copy link
Contributor Author

@willfarrell If by "last release" you mean middy@5.2.5, that's not available on npm.

@garysassano
Copy link
Contributor Author

Duplicate of #1176

@garysassano
Copy link
Contributor Author

Reopening since the issue is still present on latest version.

@garysassano garysassano reopened this May 20, 2024
@naorpeled
Copy link
Contributor

On it 🙏

@garysassano
Copy link
Contributor Author

I still get the error in 5.4.0

image

@naorpeled
Copy link
Contributor

Hey @garysassano,
using the current implementation the following two ways would work:

middy(lambdaHandler).use(eventNormalizer())

// OR

const lambdaHandler = async (event: S3Event, context: Context) => {
  await Promise.all(event.Records.map(async () => await Promise.resolve()))
}

const handler = middy<S3Event, void>().use(eventNormalizer()).handler(lambdaHandler)

regarding a fix for the above syntax that you've mentioned, I'm on it but it will take some time.

@naorpeled
Copy link
Contributor

Hey @garysassano,
I've created a PR to properly resolve this.
Waiting for Will to review and hopefully we'll merge this within the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants