Skip to content

Commit a8e27e8

Browse files
committed
ref(google-cloud-serverless/v9): Update event functions to avoid any
1 parent b9899bb commit a8e27e8

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

packages/google-cloud-serverless/src/gcpfunction/events.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ export function wrapEventFunction(
2222
return proxyFunction(fn, f => domainify(_wrapEventFunction(f, wrapOptions)));
2323
}
2424

25-
/** */
2625
function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>(
2726
fn: F,
2827
wrapOptions: Partial<EventFunctionWrapperOptions> = {},
29-
): (...args: Parameters<F>) => ReturnType<F> | Promise<void> {
28+
): (...args: Parameters<F>) => void | Promise<void> {
3029
const options: EventFunctionWrapperOptions = {
3130
flushTimeout: 2000,
3231
...wrapOptions,
3332
};
34-
return (...eventFunctionArguments: Parameters<F>): ReturnType<F> | Promise<void> => {
33+
return (...eventFunctionArguments: Parameters<F>): void | Promise<void> => {
3534
const [data, context, callback] = eventFunctionArguments;
3635

3736
return startSpanManual(
@@ -47,8 +46,8 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
4746
const scope = getCurrentScope();
4847
scope.setContext('gcp.function.context', { ...context });
4948

50-
const newCallback = domainify((...args: unknown[]) => {
51-
if (args[0] !== null && args[0] !== undefined) {
49+
const newCallback = domainify((...args): void => {
50+
if (args[0] != null) {
5251
captureException(args[0], scope => markEventUnhandled(scope));
5352
}
5453
span.end();

packages/google-cloud-serverless/src/gcpfunction/general.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import type { Request, Response } from 'express';
22

3-
export interface HttpFunction {
4-
(req: Request, res: Response): any; // eslint-disable-line @typescript-eslint/no-explicit-any
5-
}
3+
export type HttpFunction = (req: Request, res: Response) => void;
64

7-
export interface EventFunction {
8-
(data: Record<string, any>, context: Context): any; // eslint-disable-line @typescript-eslint/no-explicit-any
9-
}
5+
export type EventFunction = (data: Record<string, unknown>, context: Context) => void;
106

11-
export interface EventFunctionWithCallback {
12-
(data: Record<string, any>, context: Context, callback: Function): any; // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
13-
}
7+
export type EventFunctionWithCallback = (
8+
data: Record<string, unknown>,
9+
context: Context,
10+
// eslint-disable-next-line @typescript-eslint/ban-types
11+
callback: Function,
12+
) => void;
1413

15-
export interface CloudEventFunction {
16-
(cloudevent: CloudEventsContext): any; // eslint-disable-line @typescript-eslint/no-explicit-any
17-
}
14+
export type CloudEventFunction = (cloudevent: CloudEventsContext) => void;
1815

19-
export interface CloudEventFunctionWithCallback {
20-
(cloudevent: CloudEventsContext, callback: Function): any; // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
21-
}
16+
// eslint-disable-next-line @typescript-eslint/ban-types
17+
export type CloudEventFunctionWithCallback = (cloudevent: CloudEventsContext, callback: Function) => void;
2218

2319
export interface CloudFunctionsContext {
2420
eventId?: string;

packages/google-cloud-serverless/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export function domainify<A extends unknown[], R>(fn: (...args: A) => R): (...ar
1616
* @returns wrapped function
1717
*/
1818
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19-
export function proxyFunction<A extends any[], R, F extends (...args: A) => R>(
19+
export function proxyFunction<F extends (...args: any[]) => unknown>(
2020
source: F,
2121
wrap: (source: F) => F,
2222
overrides?: Record<PropertyKey, unknown>,
2323
): F {
2424
const wrapper = wrap(source);
2525
const handler: ProxyHandler<F> = {
26-
apply: <T>(_target: F, thisArg: T, args: A) => {
26+
apply: <T>(_target: F, thisArg: T, args: Parameters<F>) => {
2727
return wrapper.apply(thisArg, args);
2828
},
2929
};

0 commit comments

Comments
 (0)