mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
[aws-lambda] Rutime node8.10 support. (#24823)
Bump version to 8.10 to match current runtime, allow returning result promises in handlers.
This commit is contained in:
committed by
Mohamed Hegazy
parent
e2efee7a56
commit
78350168c5
@@ -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
|
||||
|
||||
9
types/aws-lambda/index.d.ts
vendored
9
types/aws-lambda/index.d.ts
vendored
@@ -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>
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user