Skip to content

Commit 331e14e

Browse files
authored
Fix "functions.https.HttpsError is not a constructor" (#949)
* Fix "functions.https.HttpsError is not a constructor" It turns out that type aliases in TypeScript don't copy constructors. Replacing "export type Foo = common.Foo" with "import { Foo } from common; export { Foo }" is lossless and fixes the bug. * Lint fixes
1 parent 1d80b5f commit 331e14e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/providers/https.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
import * as express from 'express';
2424

2525
import { HttpsFunction, optionsToTrigger, Runnable } from '../cloud-functions';
26-
import * as common from '../common/providers/https';
26+
import {
27+
CallableContext,
28+
FunctionsErrorCode,
29+
HttpsError,
30+
onCallHandler,
31+
Request,
32+
} from '../common/providers/https';
2733
import { DeploymentOptions } from '../function-configuration';
2834

29-
export type Request = common.Request;
30-
export type CallableContext = common.CallableContext;
31-
export type FunctionsErrorCode = common.FunctionsErrorCode;
32-
export type HttpsError = common.HttpsError;
35+
export { Request, CallableContext, FunctionsErrorCode, HttpsError };
3336

3437
/**
3538
* Handle HTTP requests.
@@ -74,10 +77,7 @@ export function _onCallWithOptions(
7477
handler: (data: any, context: CallableContext) => any | Promise<any>,
7578
options: DeploymentOptions
7679
): HttpsFunction & Runnable<any> {
77-
const func: any = common.onCallHandler(
78-
{ origin: true, methods: 'POST' },
79-
handler
80-
);
80+
const func: any = onCallHandler({ origin: true, methods: 'POST' }, handler);
8181

8282
func.__trigger = {
8383
labels: {},

src/v2/providers/https.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
import * as cors from 'cors';
2424
import * as express from 'express';
2525

26-
import * as common from '../../common/providers/https';
26+
import {
27+
CallableRequest,
28+
FunctionsErrorCode,
29+
HttpsError,
30+
onCallHandler,
31+
Request,
32+
} from '../../common/providers/https';
2733
import * as options from '../options';
2834

29-
export type Request = common.Request;
30-
31-
export type CallableRequest<T = any> = common.CallableRequest<T>;
32-
export type FunctionsErrorCode = common.FunctionsErrorCode;
33-
export type HttpsError = common.HttpsError;
35+
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
3436

3537
export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
3638
region?:
@@ -142,7 +144,7 @@ export function onCall<T = any, Return = any | Promise<any>>(
142144
}
143145

144146
const origin = 'cors' in opts ? opts.cors : true;
145-
const func: any = common.onCallHandler({ origin, methods: 'POST' }, handler);
147+
const func: any = onCallHandler({ origin, methods: 'POST' }, handler);
146148

147149
Object.defineProperty(func, '__trigger', {
148150
get: () => {

0 commit comments

Comments
 (0)