From d74f5c36d30cdc53cb76ab0772655d354a203f33 Mon Sep 17 00:00:00 2001 From: abrindam Date: Fri, 25 Sep 2020 20:22:21 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#48199=20"newrelic"?= =?UTF-8?q?=20package:=20Correct=20typing=20of=20setLambdaHandler()=20by?= =?UTF-8?q?=20@abrindam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrew Brindamour --- types/newrelic/index.d.ts | 9 +++++---- types/newrelic/newrelic-tests.ts | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/types/newrelic/index.d.ts b/types/newrelic/index.d.ts index 202dd95b74..b6166e7608 100644 --- a/types/newrelic/index.d.ts +++ b/types/newrelic/index.d.ts @@ -7,6 +7,7 @@ // Kenneth Aasan // Jon Flaishans // Dylan Smith +// BlueJeans by Verizon // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api @@ -356,12 +357,12 @@ export function getLinkingMetadata(omitSupportability?: boolean): LinkingMetadat export function getTraceMetadata(): TraceMetadata; /** - * Wraps an AWS Lambda function with NewRelic instrumentation and returns the value of the handler + * Wraps an AWS Lambda function with NewRelic instrumentation and returns the wrapped function. * - * The handler is a callback function whose value is returned from setLambdaHandler - * Returns the value returned by handler + * The handler should be an AWS Lambda handler function. + * Returns a function with identical signature to the provided handler function. */ -export function setLambdaHandler(handler: (...args: any[]) => T): T; +export function setLambdaHandler any>(handler: T): T; export interface Instrument { (opts: { moduleName: string; onRequire: () => void; onError?: (err: Error) => void }): void; diff --git a/types/newrelic/newrelic-tests.ts b/types/newrelic/newrelic-tests.ts index ac4d386f8d..09f4d6cdd1 100644 --- a/types/newrelic/newrelic-tests.ts +++ b/types/newrelic/newrelic-tests.ts @@ -122,4 +122,6 @@ newrelic.getLinkingMetadata(); newrelic.getLinkingMetadata(true); newrelic.getTraceMetadata(); -newrelic.setLambdaHandler(() => void 0); // $ExpectType undefined +newrelic.setLambdaHandler(() => void 0); // $ExpectType () => undefined +newrelic.setLambdaHandler((event: unknown, context: unknown) => ({ statusCode: 200, body: "Hello!" })); // $ExpectType (event: unknown, context: unknown) => { statusCode: number; body: string; } +newrelic.setLambdaHandler({some: "object"}); // $ExpectError