diff --git a/packages/google-cloud-serverless/src/gcpfunction/events.ts b/packages/google-cloud-serverless/src/gcpfunction/events.ts index 319329ccf28f..1ac9115b0817 100644 --- a/packages/google-cloud-serverless/src/gcpfunction/events.ts +++ b/packages/google-cloud-serverless/src/gcpfunction/events.ts @@ -22,16 +22,15 @@ export function wrapEventFunction( return proxyFunction(fn, f => domainify(_wrapEventFunction(f, wrapOptions))); } -/** */ function _wrapEventFunction( fn: F, wrapOptions: Partial = {}, -): (...args: Parameters) => ReturnType | Promise { +): (...args: Parameters) => void | Promise { const options: EventFunctionWrapperOptions = { flushTimeout: 2000, ...wrapOptions, }; - return (...eventFunctionArguments: Parameters): ReturnType | Promise => { + return (...eventFunctionArguments: Parameters): void | Promise => { const [data, context, callback] = eventFunctionArguments; return startSpanManual( @@ -47,8 +46,8 @@ function _wrapEventFunction const scope = getCurrentScope(); scope.setContext('gcp.function.context', { ...context }); - const newCallback = domainify((...args: unknown[]) => { - if (args[0] !== null && args[0] !== undefined) { + const newCallback = domainify((...args): void => { + if (args[0] != null) { captureException(args[0], scope => markEventUnhandled(scope)); } span.end(); diff --git a/packages/google-cloud-serverless/src/gcpfunction/general.ts b/packages/google-cloud-serverless/src/gcpfunction/general.ts index f819bd5aaaf3..2c9a7df3e698 100644 --- a/packages/google-cloud-serverless/src/gcpfunction/general.ts +++ b/packages/google-cloud-serverless/src/gcpfunction/general.ts @@ -1,24 +1,20 @@ import type { Request, Response } from 'express'; -export interface HttpFunction { - (req: Request, res: Response): any; // eslint-disable-line @typescript-eslint/no-explicit-any -} +export type HttpFunction = (req: Request, res: Response) => void; -export interface EventFunction { - (data: Record, context: Context): any; // eslint-disable-line @typescript-eslint/no-explicit-any -} +export type EventFunction = (data: Record, context: Context) => void; -export interface EventFunctionWithCallback { - (data: Record, context: Context, callback: Function): any; // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types -} +export type EventFunctionWithCallback = ( + data: Record, + context: Context, + // eslint-disable-next-line @typescript-eslint/ban-types + callback: Function, +) => void; -export interface CloudEventFunction { - (cloudevent: CloudEventsContext): any; // eslint-disable-line @typescript-eslint/no-explicit-any -} +export type CloudEventFunction = (cloudevent: CloudEventsContext) => void; -export interface CloudEventFunctionWithCallback { - (cloudevent: CloudEventsContext, callback: Function): any; // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types -} +// eslint-disable-next-line @typescript-eslint/ban-types +export type CloudEventFunctionWithCallback = (cloudevent: CloudEventsContext, callback: Function) => void; export interface CloudFunctionsContext { eventId?: string; diff --git a/packages/google-cloud-serverless/src/utils.ts b/packages/google-cloud-serverless/src/utils.ts index 8e33f55b51cd..f55569c82f9b 100644 --- a/packages/google-cloud-serverless/src/utils.ts +++ b/packages/google-cloud-serverless/src/utils.ts @@ -17,14 +17,14 @@ export function domainify(fn: (...args: A) => R): (...ar * @returns wrapped function */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function proxyFunction R>( +export function proxyFunction unknown>( source: F, wrap: (source: F) => F, overrides?: Record, ): F { const wrapper = wrap(source); const handler: ProxyHandler = { - apply: (_target: F, thisArg: T, args: A) => { + apply: (_target: F, thisArg: T, args: Parameters) => { return wrapper.apply(thisArg, args); }, };