Skip to content

Commit d93a074

Browse files
authored
Merge pull request #106 from FirebasePrivate/inlined.fix-exports
I previously tried `export * as database from './providers/database'` and when that syntax didn't work I tried ```ts import * as databaseProvider from './providers/database' export const database = databaseProvider; ``` because `export database` didn't work. It turns out the right syntax was just `export {database}`, which isn't documented in the TS docs because it's an ES6 standard. ## Bug Explanation In TypeScript things are either types or values. A namespace is the only thing that can be both. We weren't able to name `functions.auth.UserRecord` in the past because we weren't actually exporting the namespace! ```ts export const auth = authProvider; ``` created a new l-value (auth) that was a narrower type than authProvider was. Effectively the namespace got downcast to a value in the export! CC @jwngr and @davideast for FYI since this is a really cool TypeScript lesson.
2 parents b9d908e + f61eb06 commit d93a074

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@
2121
// SOFTWARE.
2222

2323
// Providers:
24-
import * as authProvider from './providers/auth';
25-
import * as databaseProvider from './providers/database';
26-
import * as pubsubProvider from './providers/pubsub';
27-
import * as storageProvider from './providers/storage';
28-
import * as httpsProvider from './providers/https';
29-
30-
export const auth = authProvider;
31-
export const database = databaseProvider;
32-
export const pubsub = pubsubProvider;
33-
export const storage = storageProvider;
34-
export const https = httpsProvider;
24+
import * as auth from './providers/auth';
25+
import * as database from './providers/database';
26+
import * as pubsub from './providers/pubsub';
27+
import * as storage from './providers/storage';
28+
import * as https from './providers/https';
29+
export {auth, database, pubsub, storage, https};
3530

3631
// Exported root types:
3732
export * from './config';

src/providers/https.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { TriggerAnnotated } from '../cloud-functions';
2424
import {Request, Response} from 'express';
25+
export {Request, Response};
2526

2627
export function onRequest(
2728
handler: (req: Request, resp: Response) => void

0 commit comments

Comments
 (0)