Skip to content

Commit 62b5e22

Browse files
authored
Create typings for the interop API (#4696)
* use hande made index.d.ts in compat for backward compatibility * auto-generate overloads * handle type parameters * preserve type parameters * overloads for auth-exp * add overloads to firestore compat * export all public types from auth-exp * add overloads to storage compat * add overloads to analytics compat * add overloads to functions compat * add overloads to messaging compat * add overloads to perf compat * add overloads to rc compat * revert firebase/compat typings * address comments
1 parent 9323e9a commit 62b5e22

File tree

24 files changed

+430
-59
lines changed

24 files changed

+430
-59
lines changed

common/api-review/auth-exp.api.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export interface Auth {
8686
readonly emulatorConfig: EmulatorConfig | null;
8787
languageCode: string | null;
8888
readonly name: string;
89-
// Warning: (ae-forgotten-export) The symbol "NextOrObserver" needs to be exported by the entry point index.d.ts
9089
onAuthStateChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9190
onIdTokenChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9291
setPersistence(persistence: Persistence): Promise<void>;
@@ -153,6 +152,8 @@ export const browserSessionPersistence: Persistence;
153152
// @public
154153
export function checkActionCode(auth: Auth, oobCode: string): Promise<ActionCodeInfo>;
155154

155+
export { CompleteFn }
156+
156157
// @public
157158
export interface Config {
158159
apiHost: string;
@@ -184,6 +185,16 @@ export const debugErrorMap: AuthErrorMap;
184185
// @public
185186
export function deleteUser(user: User): Promise<void>;
186187

188+
// @public (undocumented)
189+
export interface Dependencies {
190+
// (undocumented)
191+
errorMap?: AuthErrorMap;
192+
// (undocumented)
193+
persistence?: Persistence | Persistence[];
194+
// (undocumented)
195+
popupRedirectResolver?: PopupRedirectResolver;
196+
}
197+
187198
// @public
188199
export class EmailAuthCredential extends AuthCredential {
189200
// (undocumented)
@@ -216,6 +227,8 @@ export class EmailAuthProvider implements AuthProvider {
216227
readonly providerId = ProviderId.PASSWORD;
217228
}
218229

230+
export { ErrorFn }
231+
219232
// Warning: (ae-forgotten-export) The symbol "BaseOAuthProvider" needs to be exported by the entry point index.d.ts
220233
//
221234
// @public
@@ -248,10 +261,8 @@ export function getIdToken(user: User, forceRefresh?: boolean): Promise<string>;
248261
// @public
249262
export function getIdTokenResult(user: User, forceRefresh?: boolean): Promise<IdTokenResult>;
250263

251-
// Warning: (ae-forgotten-export) The symbol "MultiFactorError" needs to be exported by the entry point index.d.ts
252-
//
253264
// @public
254-
export function getMultiFactorResolver(auth: Auth, error: MultiFactorError_2): MultiFactorResolver;
265+
export function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver;
255266

256267
// @public
257268
export function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): Promise<UserCredential | null>;
@@ -290,8 +301,6 @@ export interface IdTokenResult {
290301
// @public
291302
export const indexedDBLocalPersistence: Persistence;
292303

293-
// Warning: (ae-forgotten-export) The symbol "Dependencies" needs to be exported by the entry point index.d.ts
294-
//
295304
// @public (undocumented)
296305
export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth;
297306

@@ -353,6 +362,9 @@ export interface MultiFactorUser {
353362
unenroll(option: MultiFactorInfo | string): Promise<void>;
354363
}
355364

365+
// @public
366+
export type NextOrObserver<T> = NextFn<T | null> | Observer<T | null>;
367+
356368
// @public
357369
export class OAuthCredential extends AuthCredential {
358370
accessToken?: string;
@@ -645,6 +657,8 @@ export class TwitterAuthProvider extends BaseOAuthProvider {
645657
// @public
646658
export function unlink(user: User, providerId: ProviderId): Promise<User>;
647659

660+
export { Unsubscribe }
661+
648662
// @public
649663
export function updateCurrentUser(auth: Auth, user: User | null): Promise<void>;
650664

common/api-review/messaging-exp.api.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
import { FirebaseApp } from '@firebase/app-exp';
7+
import { FirebaseApp } from '@firebase/app';
88
import { NextFn } from '@firebase/util';
99
import { Observer } from '@firebase/util';
1010
import { Unsubscribe } from '@firebase/util';
@@ -52,6 +52,8 @@ export interface MessagePayload {
5252
notification?: NotificationPayload;
5353
}
5454

55+
export { NextFn }
56+
5557
// @public
5658
export interface NotificationPayload {
5759
// (undocumented)
@@ -62,6 +64,8 @@ export interface NotificationPayload {
6264
title?: string;
6365
}
6466

67+
export { Observer }
68+
6569
// Warning: (ae-internal-missing-underscore) The name "onBackgroundMessage" should be prefixed with an underscore because the declaration is marked as @internal
6670
//
6771
// @internal
@@ -70,6 +74,8 @@ export function onBackgroundMessage(messaging: FirebaseMessaging, nextOrObserver
7074
// @public
7175
export function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
7276

77+
export { Unsubscribe }
78+
7379

7480
// (No @packageDocumentation comment for this package)
7581

packages-exp/analytics-compat/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
3636
"build": "rollup -c",
3737
"build:deps": "lerna run --scope @firebase/analytics-compat --include-dependencies build",
38-
"build:release": "rollup -c rollup.config.release.js",
38+
"build:release": "rollup -c rollup.config.release.js && yarn add-compat-overloads",
3939
"dev": "rollup -c -w",
4040
"test": "run-p lint test:browser",
4141
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
4242
"test:browser": "karma start --single-run",
43-
"test:browser:debug": "karma start --browsers=Chrome --auto-watch"
43+
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
44+
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../analytics-exp/dist/analytics-exp-public.d.ts -o dist/src/index.d.ts -a -r Analytics:FirebaseAnalytics -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/analytics"
4445
},
4546
"typings": "dist/src/index.d.ts",
4647
"dependencies": {

packages-exp/auth-compat-exp/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
EmailAuthProvider_Instance,
3232
FacebookAuthProvider,
3333
FacebookAuthProvider_Instance,
34-
FirebaseAuth,
34+
FirebaseAuth as AuthCompat,
3535
GithubAuthProvider,
3636
GithubAuthProvider_Instance,
3737
GoogleAuthProvider,
@@ -56,15 +56,15 @@ const AUTH_TYPE = 'auth-compat';
5656

5757
declare module '@firebase/component' {
5858
interface NameServiceMapping {
59-
'auth-compat': FirebaseAuth;
59+
'auth-compat': AuthCompat;
6060
}
6161
}
6262

6363
declare module '@firebase/app-compat' {
6464
interface FirebaseNamespace {
6565
auth: {
66-
(app?: FirebaseApp): FirebaseAuth;
67-
Auth: typeof FirebaseAuth;
66+
(app?: FirebaseApp): AuthCompat;
67+
Auth: typeof AuthCompat;
6868
EmailAuthProvider: typeof EmailAuthProvider;
6969
EmailAuthProvider_Instance: typeof EmailAuthProvider_Instance;
7070
FacebookAuthProvider: typeof FacebookAuthProvider;
@@ -85,7 +85,7 @@ declare module '@firebase/app-compat' {
8585
};
8686
}
8787
interface FirebaseApp {
88-
auth?(): FirebaseAuth;
88+
auth?(): AuthCompat;
8989
}
9090
}
9191

packages-exp/auth-compat-exp/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1717
"build": "rollup -c",
1818
"build:deps": "lerna run --scope @firebase/auth-compat --include-dependencies build",
19-
"build:release": "rollup -c rollup.config.release.js",
19+
"build:release": "rollup -c rollup.config.release.js && yarn add-compat-overloads",
2020
"dev": "rollup -c -w",
2121
"test": "run-p lint test:all",
2222
"test:all": "run-p test:browser test:node",
@@ -26,7 +26,8 @@
2626
"test:node": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts",
2727
"test:node:integration": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --integration",
2828
"test:webdriver": "rollup -c test/integration/webdriver/static/rollup.config.js && ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --webdriver",
29-
"test:integration": "run-s test:browser:integration test:node:integration test:webdriver"
29+
"test:integration": "run-s test:browser:integration test:node:integration test:webdriver",
30+
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../auth-exp/dist/auth-exp-public.d.ts -o dist/auth-compat-exp/index.d.ts -a -r Auth:AuthCompat -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/auth"
3031
},
3132
"peerDependencies": {
3233
"@firebase/app-compat": "0.x"

packages-exp/auth-exp/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ export {
6565
UserInfo,
6666
UserMetadata,
6767
UserProfile,
68-
PhoneInfoOptions
68+
PhoneInfoOptions,
69+
Dependencies,
70+
NextOrObserver,
71+
ErrorFn,
72+
CompleteFn,
73+
Unsubscribe
6974
} from './src/model/public_types';
7075

7176
// Core functionality shared by all clients

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ import {
2525
Persistence,
2626
PopupRedirectResolver,
2727
User,
28-
UserCredential
28+
UserCredential,
29+
CompleteFn,
30+
ErrorFn,
31+
NextFn,
32+
Unsubscribe
2933
} from '../../model/public_types';
3034
import {
31-
CompleteFn,
3235
createSubscribe,
3336
ErrorFactory,
34-
ErrorFn,
35-
NextFn,
3637
Observer,
37-
Subscribe,
38-
Unsubscribe
38+
Subscribe
3939
} from '@firebase/util';
4040

4141
import { AuthInternal, ConfigInternal } from '../../model/auth';

packages-exp/auth-exp/src/core/auth/initialize.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
*/
1717

1818
import { _getProvider, FirebaseApp } from '@firebase/app-exp';
19-
import { Auth } from '../../model/public_types';
19+
import { Auth, Dependencies } from '../../model/public_types';
2020

21-
import { Dependencies } from '../../model/auth';
2221
import { AuthErrorCode } from '../errors';
2322
import { PersistenceInternal } from '../persistence';
2423
import { _fail } from '../util/assert';

packages-exp/auth-exp/src/core/auth/register.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { _registerComponent, registerVersion } from '@firebase/app-exp';
19-
import { Config } from '../../model/public_types';
19+
import { Config, Dependencies } from '../../model/public_types';
2020
import { Component, ComponentType } from '@firebase/component';
2121

2222
import { version } from '../../../package.json';
@@ -25,7 +25,6 @@ import { _assert } from '../util/assert';
2525
import { _getClientVersion, ClientPlatform } from '../util/version';
2626
import { _castAuth, AuthImpl, DefaultConfig } from './auth_impl';
2727
import { AuthInterop } from './firebase_internal';
28-
import { Dependencies } from '../../model/auth';
2928
import { _initializeAuthInstance } from './initialize';
3029

3130
export const enum _ComponentName {

packages-exp/auth-exp/src/core/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Auth, NextOrObserver, Persistence, User } from '../model/public_types';
19-
import { CompleteFn, ErrorFn, Unsubscribe } from '@firebase/util';
18+
import {
19+
Auth,
20+
NextOrObserver,
21+
Persistence,
22+
User,
23+
CompleteFn,
24+
ErrorFn,
25+
Unsubscribe
26+
} from '../model/public_types';
2027

2128
export { debugErrorMap, prodErrorMap } from './errors';
2229

packages-exp/auth-exp/src/model/auth.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
import {
1919
Auth,
20-
AuthErrorMap,
2120
AuthSettings,
2221
Config,
2322
EmulatorConfig,
24-
Persistence,
2523
PopupRedirectResolver,
2624
User
2725
} from './public_types';
@@ -77,9 +75,3 @@ export interface AuthInternal extends Auth {
7775
useDeviceLanguage(): void;
7876
signOut(): Promise<void>;
7977
}
80-
81-
export interface Dependencies {
82-
persistence?: Persistence | Persistence[];
83-
popupRedirectResolver?: PopupRedirectResolver;
84-
errorMap?: AuthErrorMap;
85-
}

packages-exp/auth-exp/src/model/public_types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Unsubscribe
2525
} from '@firebase/util';
2626

27+
export { CompleteFn, ErrorFn, NextFn, Unsubscribe };
2728
/**
2829
* Enumeration of supported providers.
2930
*
@@ -1170,3 +1171,12 @@ export interface EmulatorConfig {
11701171
* @public
11711172
*/
11721173
export interface AuthErrorMap {}
1174+
1175+
/**
1176+
* @public
1177+
*/
1178+
export interface Dependencies {
1179+
persistence?: Persistence | Persistence[];
1180+
popupRedirectResolver?: PopupRedirectResolver;
1181+
errorMap?: AuthErrorMap;
1182+
}

packages-exp/functions-compat/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@
3535
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
3636
"build": "rollup -c",
3737
"build:deps": "lerna run --scope @firebase/functions-compat --include-dependencies build",
38-
"build:release": "rollup -c rollup.config.release.js",
38+
"build:release": "rollup -c rollup.config.release.js && yarn add-compat-overloads",
3939
"dev": "rollup -c -w",
4040
"test": "run-p lint test:all",
4141
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
4242
"test:all": "run-p test:browser test:node",
4343
"test:browser": "karma start --single-run",
4444
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
4545
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
46-
"test:emulator": "env FIREBASE_FUNCTIONS_HOST=http://localhost FIREBASE_FUNCTIONS_PORT=5005 run-p test:node"
46+
"test:emulator": "env FIREBASE_FUNCTIONS_HOST=http://localhost FIREBASE_FUNCTIONS_PORT=5005 run-p test:node",
47+
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../functions-exp/dist/functions-exp-public.d.ts -o dist/src/index.d.ts -a -r Functions:types.FirebaseFunctions -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/functions"
4748
},
4849
"typings": "dist/src/index.d.ts",
4950
"dependencies": {

packages-exp/messaging-compat/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1919
"build": "rollup -c",
2020
"build:deps": "lerna run --scope @firebase/'messaging-compat' --include-dependencies build",
21-
"build:release": "rollup -c rollup.config.release.js",
21+
"build:release": "rollup -c rollup.config.release.js && yarn add-compat-overloads",
2222
"dev": "rollup -c -w",
2323
"test": "run-p test:karma",
2424
"test:ci": "node ../../scripts/run_tests_in_ci.js",
2525
"test:karma": "karma start --single-run",
2626
"test:debug": "karma start --browsers=Chrome --auto-watch",
27-
"type-check": "tsc --noEmit"
27+
"type-check": "tsc --noEmit",
28+
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../messaging-exp/dist/messaging-exp-public.d.ts -o dist/src/index.d.ts -a -r FirebaseMessaging:MessagingCompat -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/messaging"
2829
},
2930
"peerDependencies": {
3031
"@firebase/app-compat": "0.x"

packages-exp/messaging-exp/src/api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseMessaging, MessagePayload } from './interfaces/public-types';
19-
import { NextFn, Observer, Unsubscribe } from '@firebase/util';
18+
import {
19+
FirebaseMessaging,
20+
MessagePayload,
21+
NextFn,
22+
Observer,
23+
Unsubscribe
24+
} from './interfaces/public-types';
2025

2126
import { MessagingService } from './messaging-service';
2227
import { Provider } from '@firebase/component';

packages-exp/messaging-exp/src/api/onBackgroundMessage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
*/
1717

1818
import { ERROR_FACTORY, ErrorCode } from '../util/errors';
19-
import { NextFn, Observer, Unsubscribe } from '@firebase/util';
2019

21-
import { MessagePayload } from '../interfaces/public-types';
20+
import {
21+
MessagePayload,
22+
NextFn,
23+
Observer,
24+
Unsubscribe
25+
} from '../interfaces/public-types';
2226
import { MessagingService } from '../messaging-service';
2327
import { SwController } from '../listeners/sw-controller';
2428

0 commit comments

Comments
 (0)