Skip to content

Commit 3446ca3

Browse files
authored
feat(functions): typescript definitions for httpsCallable and httpsCallableFromUrl (#7762)
* feat(functions): Enable specification of input and response types for httpsCallable and httpsCallableFromUrl functions * lint * update to match upstream typings
1 parent 424b9d9 commit 3446ca3

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

packages/functions/lib/index.d.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export namespace FirebaseFunctionsTypes {
117117
/**
118118
* An HttpsCallableResult wraps a single result from a function call.
119119
*/
120-
export interface HttpsCallableResult {
121-
readonly data: any;
120+
export interface HttpsCallableResult<ResponseData = unknown> {
121+
readonly data: ResponseData;
122122
}
123123

124124
/**
@@ -128,33 +128,33 @@ export namespace FirebaseFunctionsTypes {
128128
* #### Example
129129
*
130130
* ```js
131-
* // Create a HttpsCallable instance
132-
* const instance = firebase.functions().httpsCallable('order');
131+
* // Create an HttpsCallable reference
132+
* const reference = firebase.functions().httpsCallable('order');
133133
*
134134
* try {
135-
* const response = await instance({
135+
* const response = await reference({
136136
* id: '12345',
137137
* });
138138
* } catch (e) {
139139
* console.error(e);
140140
* }
141141
* ```
142142
*/
143-
export interface HttpsCallable {
144-
(data?: any): Promise<HttpsCallableResult>;
143+
export interface HttpsCallable<RequestData = unknown, ResponseData = unknown> {
144+
(data?: RequestData | null): Promise<HttpsCallableResult<ResponseData>>;
145145
}
146146

147147
/**
148-
* An HttpsCallableOptions object that can be passed as the second argument to `firebase.functions().httpsCallable(name, HttpsCallableOptions)`.
148+
* An interface for metadata about how calls should be executed. An instance of HttpsCallableOptions can be passed as the second argument to `firebase.functions().httpsCallable(name, httpsCallableOptions)`.
149149
**/
150150
export interface HttpsCallableOptions {
151151
/**
152-
* The timeout property allows you to control how long the application will wait for the cloud function to respond in milliseconds.
152+
* The timeout property is the time in milliseconds after which to cancel if there is no response. Default is 70000.
153153
*
154154
* #### Example
155155
*
156156
*```js
157-
* // The below will wait 7 seconds for a response from the cloud function before an error is thrown
157+
* // The below will wait 7 seconds for a response from the cloud function before an error is thrown.
158158
* try {
159159
* const instance = firebase.functions().httpsCallable('order', { timeout: 7000 });
160160
* const response = await instance({
@@ -316,16 +316,15 @@ export namespace FirebaseFunctionsTypes {
316316
*/
317317
export class Module extends FirebaseModule {
318318
/**
319-
* Gets an `HttpsCallable` instance that refers to the function with the given
320-
* name.
319+
* Returns a reference to the callable HTTPS trigger with the given name.
321320
*
322321
* #### Example
323322
*
324323
* ```js
325-
* const instance = firebase.functions().httpsCallable('order');
324+
* const reference = firebase.functions().httpsCallable('order');
326325
*
327326
* try {
328-
* const response = await instance({
327+
* const response = await reference({
329328
* id: '12345',
330329
* });
331330
* } catch (e) {
@@ -334,21 +333,23 @@ export namespace FirebaseFunctionsTypes {
334333
* ```
335334
*
336335
* @param name The name of the https callable function.
337-
* @return The `HttpsCallable` instance.
336+
* @return The `HttpsCallable` reference.
338337
*/
339-
httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
338+
httpsCallable<RequestData = unknown, ResponseData = unknown>(
339+
name: string,
340+
options?: HttpsCallableOptions,
341+
): HttpsCallable<RequestData, ResponseData>;
340342

341343
/**
342-
* Gets an `HttpsCallable` instance that refers to the function with the given
343-
* URL.
344+
* Returns a reference to the callable HTTPS trigger with the specified url.
344345
*
345346
* #### Example
346347
*
347348
* ```js
348-
* const instance = firebase.functions().httpsCallable('order');
349+
* const reference = firebase.functions().httpsCallable('order');
349350
*
350351
* try {
351-
* const response = await instance({
352+
* const response = await reference({
352353
* id: '12345',
353354
* });
354355
* } catch (e) {
@@ -357,9 +358,12 @@ export namespace FirebaseFunctionsTypes {
357358
* ```
358359
*
359360
* @param name The name of the https callable function.
360-
* @return The `HttpsCallable` instance.
361+
* @return The `HttpsCallable` reference.
361362
*/
362-
httpsCallableFromUrl(url: string, options?: HttpsCallableOptions): HttpsCallable;
363+
httpsCallableFromUrl<RequestData = unknown, ResponseData = unknown>(
364+
url: string,
365+
options?: HttpsCallableOptions,
366+
): HttpsCallable<RequestData, ResponseData>;
363367

364368
/**
365369
* Changes this instance to point to a Cloud Functions emulator running locally.

0 commit comments

Comments
 (0)