diff --git a/spec/v1/providers/https.spec.ts b/spec/v1/providers/https.spec.ts index 3fc736952..8f328b345 100644 --- a/spec/v1/providers/https.spec.ts +++ b/spec/v1/providers/https.spec.ts @@ -115,7 +115,7 @@ describe("#onCall", () => { }); it("has a .run method", () => { - const cf = https.onCall((d, c) => { + const cf = https.onCall((d, c) => { return { data: d, context: c }; }); diff --git a/spec/v2/providers/https.spec.ts b/spec/v2/providers/https.spec.ts index 1d7d30ae3..e388400a1 100644 --- a/spec/v2/providers/https.spec.ts +++ b/spec/v2/providers/https.spec.ts @@ -454,8 +454,8 @@ describe("onCall", () => { https.onCall( (request: https.CallableRequest) => `hello, ${request.data}!` ); - https.onCall((request: https.CallableRequest) => `hello, ${request.data}!`); - https.onCall((request: https.CallableRequest) => `hello, ${request.data}!`); + https.onCall((request) => `hello, ${request.data}!`); + https.onCall((request) => `hello, ${request.data}!`); https.onCall((request: https.CallableRequest) => `Hello, ${request.data}`); https.onCall((request: https.CallableRequest) => `Hello, ${request.data}`); }); diff --git a/src/v1/function-builder.ts b/src/v1/function-builder.ts index c7e5daa3e..9538411bb 100644 --- a/src/v1/function-builder.ts +++ b/src/v1/function-builder.ts @@ -340,8 +340,9 @@ export class FunctionBuilder { * Declares a callable method for clients to call using a Firebase SDK. * @param handler A method that takes a data and context and returns a value. */ - onCall: (handler: (data: any, context: https.CallableContext) => any | Promise) => - https._onCallWithOptions(handler, this.options), + onCall: ( + handler: (data: TData, context: https.CallableContext) => TReturn | Promise + ) => https._onCallWithOptions(handler, this.options), }; } diff --git a/src/v1/providers/https.ts b/src/v1/providers/https.ts index 0cdcc52c1..5be31ce4d 100644 --- a/src/v1/providers/https.ts +++ b/src/v1/providers/https.ts @@ -51,9 +51,9 @@ export function onRequest( * Declares a callable method for clients to call using a Firebase SDK. * @param handler A method that takes a data and context and returns a value. */ -export function onCall( - handler: (data: any, context: CallableContext) => any | Promise -): HttpsFunction & Runnable { +export function onCall( + handler: (data: TData, context: CallableContext) => TReturn | Promise +): HttpsFunction & Runnable { return _onCallWithOptions(handler, {}); } diff --git a/src/v2/providers/https.ts b/src/v2/providers/https.ts index eedd42e01..28c9e2d4e 100644 --- a/src/v2/providers/https.ts +++ b/src/v2/providers/https.ts @@ -187,12 +187,12 @@ export type HttpsFunction = (( /** * Creates a callable method for clients to call using a Firebase SDK. */ -export interface CallableFunction extends HttpsFunction { +export interface CallableFunction extends HttpsFunction { /** Executes the handler function with the provided data as input. Used for unit testing. * @param data - An input for the handler function. * @returns The output of the handler function. */ - run(data: CallableRequest): Return; + run(data: CallableRequest): TReturn; } /** * Handles HTTPS requests. @@ -299,26 +299,26 @@ export function onRequest( * @param handler - A function that takes a {@link https.CallableRequest}. * @returns A function that you can export and deploy. */ -export function onCall>( +export function onCall( opts: CallableOptions, - handler: (request: CallableRequest) => Return -): CallableFunction; + handler: (request: CallableRequest) => TReturn | Promise +): CallableFunction>; /** * Declares a callable method for clients to call using a Firebase SDK. * @param handler - A function that takes a {@link https.CallableRequest}. * @returns A function that you can export and deploy. */ -export function onCall>( - handler: (request: CallableRequest) => Return -): CallableFunction; -export function onCall>( - optsOrHandler: CallableOptions | ((request: CallableRequest) => Return), - handler?: (request: CallableRequest) => Return -): CallableFunction { +export function onCall( + handler: (request: CallableRequest) => TReturn | Promise +): CallableFunction>; +export function onCall( + optsOrHandler: CallableOptions | ((request: CallableRequest) => TReturn | Promise), + handler?: (request: CallableRequest) => TReturn | Promise +): CallableFunction> { let opts: CallableOptions; if (arguments.length === 1) { opts = {}; - handler = optsOrHandler as (request: CallableRequest) => Return; + handler = optsOrHandler as (request: CallableRequest) => TReturn | Promise; } else { opts = optsOrHandler as CallableOptions; }