Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions types/aws-lambda/aws-lambda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,27 @@ context.fail(str);
/* Handler */
let handler: AWSLambda.Handler = (event: any, context: AWSLambda.Context, cb: AWSLambda.Callback) => { };

// async methods return Promise, test assignability
let asyncHandler: AWSLambda.Handler = async (event: any, context: AWSLambda.Context, cb: AWSLambda.Callback) => { };
/* In node8.10 runtime, handlers may return a promise for the result value, so existing async
* handlers that return Promise<void> before calling the callback will now have a `null` result.
* Be safe and make that badly typed with a major verson bump to 8.10 so users expect the breaking change,
* since the upgrade effort should be pretty low in most cases, and it points them at a nicer solution.
*/
// $ExpectError
let legacyAsyncHandler: AWSLambda.APIGatewayProxyHandler = async (
event: AWSLambda.APIGatewayProxyEvent,
context: AWSLambda.Context,
cb: AWSLambda.Callback<AWSLambda.APIGatewayProxyResult>,
) => {
cb(null, { statusCode: 200, body: 'No longer valid' });
};

let node8AsyncHandler: AWSLambda.APIGatewayProxyHandler = async (
event: AWSLambda.APIGatewayProxyEvent,
context: AWSLambda.Context,
cb: AWSLambda.Callback<AWSLambda.APIGatewayProxyResult>,
) => {
return { statusCode: 200, body: 'Is now valid!' };
};

let inferredHandler: AWSLambda.S3Handler = (event, context, cb) => {
// $ExpectType S3Event
Expand Down
9 changes: 7 additions & 2 deletions types/aws-lambda/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for AWS Lambda
// Type definitions for AWS Lambda 8.10
// Project: http://docs.aws.amazon.com/lambda
// Definitions by: James Darbyshire <https://github.com/darbio/aws-lambda-typescript>
// Michael Skarum <https://github.com/skarum>
Expand Down Expand Up @@ -562,8 +562,13 @@ export interface KinesisStreamEvent {
* @param event – event data.
* @param context – runtime information of the Lambda function that is executing.
* @param callback – optional callback to return information to the caller, otherwise return value is null.
* @return In the node8.10 runtime, a promise for the lambda result.
*/
export type Handler<TEvent = any, TResult = any> = (event: TEvent, context: Context, callback: Callback<TResult>) => void;
export type Handler<TEvent = any, TResult = any> = (
event: TEvent,
context: Context,
callback: Callback<TResult>,
) => void | Promise<TResult>;

/**
* Optional callback parameter.
Expand Down