Skip to content

Commit 337b47d

Browse files
authored
BREAKING: Break TS build that uses functions.config() (#1757)
Type out `functions.config()` API. Use of `functions.config()` API should now cause a BUILD error at compile time. ```ts import * as functions from "firebase-functions"; import {onRequest} from "firebase-functions/https"; import * as logger from "firebase-functions/logger"; const cfg = functions.config() export const helloWorld = onRequest((request, response) => { logger.info("Hello logs!", cfg); response.send("Hello from Firebase!"); }); ``` ```bash $ npm run build > build > tsc src/index.ts:5:23 - error TS2349: This expression is not callable. Type 'never' has no call signatures. 5 const cfg = functions.config() ~~~~~~ Found 1 error in src/index.ts:5 ```
1 parent 206c838 commit 337b47d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

spec/v1/config.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ import { config } from "../../src/v1/config";
2626

2727
describe("config()", () => {
2828
it("throws an error with migration guidance", () => {
29-
expect(config).to.throw(
29+
expect(() => {
30+
// @ts-expect-error - config is deprecated and typed as never to cause a build error
31+
config();
32+
}).to.throw(
3033
Error,
3134
"functions.config() has been removed in firebase-functions v7. " +
3235
"Migrate to environment parameters using the params module. " +
3336
"Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config"
3437
);
3538
});
36-
});
39+
});

src/v1/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export { firebaseConfig } from "../common/config";
2727
* Migrate to environment parameters using the `params` module immediately.
2828
* Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config
2929
*/
30-
export function config(): Record<string, any> {
30+
export const config: never = (() => {
3131
throw new Error(
3232
"functions.config() has been removed in firebase-functions v7. " +
3333
"Migrate to environment parameters using the params module. " +
3434
"Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config"
3535
);
36-
}
36+
}) as never;

0 commit comments

Comments
 (0)