TypeScript error when using `S3Handler` type
garysassano opened this issue · comments
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.
I think this was fix in the last release. If not, would you like to submit a PR?
@willfarrell If by "last release" you mean middy@5.2.5
, that's not available on npm.
Duplicate of #1176
Reopening since the issue is still present on latest version.
On it 🙏
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.
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.