TypeScript compile error in @middy/core 5.2.4
cm-rwakatsuki opened this issue · comments
Describe the bug
After updating @middy/core from 5.2.3 to 5.2.4, an error occurred in TypeScript compile (tsc).
To Reproduce
How to reproduce the behaviour:
Sample code
- packages/server/src/lambda/handlers/api-gateway/rest-api/router.ts
import serverlessExpress from "@codegenie/serverless-express";
import middy from "@middy/core";
import express from "express";
const app = express();
export const handler = middy(serverlessExpress({ app }));
Thrown error
tsc --noEmit
src/lambda/handlers/api-gateway/rest-api/router.ts:11:30 - error TS2345: Argument of type 'Handler<any, any> & ConfigureResult<any, any>' is not assignable to parameter of type 'PluginObject | MiddyInputHandler<any, any, Context> | undefined'.
Type 'Handler<any, any> & ConfigureResult<any, any>' is not assignable to type 'MiddyInputHandler<any, any, Context>'.
Types of parameters 'callback' and 'opts' are incompatible.
Type 'MiddyHandlerObject' is not assignable to type 'Callback<any>'.
Type 'MiddyHandlerObject' provides no match for the signature '(error?: string | Error | null | undefined, result?: any): void'.
11 export const handler = middy(serverlessExpress({ app }));
Expected behaviour
tsc can run without errors.
Environment (please complete the following information):
- Node.js: 20.9.0
- Middy: 5.2.4
- AWS SDK 2.1450.0
Is this merge here the issue? #1165
The removal of the callback? Have the same issue with https://github.com/DefinitelyTyped/DefinitelyTyped/blob/7bd4a02ba62ede50a6198bd5b10712ae1a2fe6c8/types/aws-lambda/handler.d.ts#L84 the aws-lambda handler.
Still has a callback but it doesn't match the new schema
Thanks for reporting. Would someone like to put a PR together for this fix?
Same issue is reproducible with the following basic Lambda using TypeScript 5.3.3:
import { type Handler } from "aws-lambda";
import middy from "@middy/core";
const baseHandler: Handler = async (event) => {
console.log("Hello world");
};
export const handler = middy(baseHandler); // <== error here as described in issue thread
I could confirm that my issue #1182 is related to this.
After downgrading to @middy/core 5.2.3
, TypeScript stopped throwing the error.
This is really frustrating, writing a proxy function just to massage the types between middy and aws lambda here means me updating a few hundred functions across our services.
Thanks for reporting. Would someone like to put a PR together for this fix?
@willfarrell, how would you like that PR to address and resolve this issue?
I might have a possible solution in #1198. Is there any blessed soul willing to review it? :)