Middy
我正在尝试在 Lambda API 调用中使用 TyepScript 。我的部分代码:
// My types definition
import BodyRequestType from 'types';
// some code
async function myFunction (
event: { body: BodyRequestType },
callback: ??? <--
): Promise<void> {
// my code
return callback(null, {
statusCode: 200,
body: JSON.stringify(data)
});
}
export const handler = middy(myFunction);
我尝试使用:
import { Callback } from 'aws-lambda'
// then...
callback: Callback
但我得到这个错误middy(myFunction)
:
TS2345: Argument of type '(event: { body: BodyRequestType; }, callback: Callback<any>) => Promise<void>' is not assignable to
parameter of type 'AsyncHandler<Context>'.
Type '(event: { body: BodyRequestType; }, callback: Callback<any>) => Promise<void>'
is not assignable to type '(event: any, context: Context, callback: Callback<any>) => void'.
Types of parameters 'callback'and 'context' are incompatible.
Type 'Context' is not assignable to type 'Callback<any>'.
Type 'Context' provides no match for the signature '(error?: string | Error | null | undefined, result?: any): void'.
callback
我应该在myFunction的参数上使用什么类型?