17
17
18
18
import { FirebaseApp } from '@firebase/app-types' ;
19
19
import { FirebaseService } from '@firebase/app-types/private' ;
20
- import firebase from '@firebase/app' ;
21
20
import {
22
21
FirebaseFunctions ,
23
- FunctionsErrorCode ,
24
22
HttpsCallable ,
25
23
HttpsCallableResult ,
26
24
HttpsCallableOptions
@@ -34,7 +32,21 @@ import { Serializer } from '../serializer';
34
32
*/
35
33
interface HttpResponse {
36
34
status : number ;
37
- json : any ;
35
+ json : HttpResponseBody | null ;
36
+ }
37
+ /**
38
+ * Describes the shape of the HttpResponse body.
39
+ * It makes functions that would otherwise take {} able to access the
40
+ * possible elements in the body more easily
41
+ */
42
+ export interface HttpResponseBody {
43
+ data ?: unknown ;
44
+ result ?: unknown ;
45
+ error ?: {
46
+ message ?: unknown ;
47
+ status ?: unknown ;
48
+ details ?: unknown ;
49
+ } ;
38
50
}
39
51
40
52
/**
@@ -43,7 +55,7 @@ interface HttpResponse {
43
55
*
44
56
* @param millis Number of milliseconds to wait before rejecting.
45
57
*/
46
- function failAfter ( millis : number ) : Promise < HttpResponse > {
58
+ function failAfter ( millis : number ) : Promise < never > {
47
59
return new Promise ( ( _ , reject ) => {
48
60
setTimeout ( ( ) => {
49
61
reject ( new HttpsErrorImpl ( 'deadline-exceeded' , 'deadline-exceeded' ) ) ;
@@ -110,7 +122,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
110
122
* @param origin The origin of the local emulator, such as
111
123
* "http://localhost:5005".
112
124
*/
113
- useFunctionsEmulator ( origin : string ) {
125
+ useFunctionsEmulator ( origin : string ) : void {
114
126
this . emulatorOrigin = origin ;
115
127
}
116
128
@@ -119,10 +131,9 @@ export class Service implements FirebaseFunctions, FirebaseService {
119
131
* @param name The name of the trigger.
120
132
*/
121
133
httpsCallable ( name : string , options ?: HttpsCallableOptions ) : HttpsCallable {
122
- let callable = < HttpsCallable > ( data ?: any ) => {
134
+ return data => {
123
135
return this . call ( name , data , options || { } ) ;
124
136
} ;
125
- return callable ;
126
137
}
127
138
128
139
/**
@@ -156,15 +167,15 @@ export class Service implements FirebaseFunctions, FirebaseService {
156
167
json : null
157
168
} ;
158
169
}
159
- let json : any = null ;
170
+ let json : { } | null = null ;
160
171
try {
161
172
json = await response . json ( ) ;
162
173
} catch ( e ) {
163
174
// If we fail to parse JSON, it will fail the same as an empty body.
164
175
}
165
176
return {
166
177
status : response . status ,
167
- json : json
178
+ json
168
179
} ;
169
180
}
170
181
@@ -175,7 +186,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
175
186
*/
176
187
private async call (
177
188
name : string ,
178
- data : any ,
189
+ data : unknown ,
179
190
options : HttpsCallableOptions
180
191
) : Promise < HttpsCallableResult > {
181
192
const url = this . _url ( name ) ;
@@ -240,7 +251,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
240
251
}
241
252
242
253
// Decode any special types, such as dates, in the returned data.
243
- const decodedData = this . serializer . decode ( responseData ) ;
254
+ const decodedData = this . serializer . decode ( responseData as { } | null ) ;
244
255
245
256
return { data : decodedData } ;
246
257
}
0 commit comments