Skip to content

Commit aa8ee8b

Browse files
authored
fix(types): enable TypeScript libCheck & resolve type conflicts (#4306)
* chore: enable TypeScript libcheck & remove "dom" lib "dom" conflicts with @types/react-native * chore: add react types (referenced by admob types) * refactor(types, app): move "app" exports to top-level exports, rather than module declarations with namespace extensions * refactor(types): use top-level exports for module types, rather than declarations * refactor(types): for JSON config, augment existing `ReactNativeFirebase` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging * fix(types, admob): Use string-indexing rather than dot-notation for referring to interface keys * fix(types, analytics): convert missing interface to `any` * fix(types, database): missing `value` type (treated as 'any') * fix(types, dynamic-links): fix dynamic-links `onLink` function type "Function" is not generic * fix(types, firestore): add missing generic to Promise type Keep current behavior with `any` * fix(types, messaging): remove parameter initializer in typedef Only allowed in implementations * fix(types, messaging): avoid implicit `any` via `void` return type for `setBackgroundMessageHandler` * fix(types, ml-vision): import non-ambient types in BarcodeDetectorTypes * fix(types, ml-vision): import non-ambient types in root module from BarcodeDetectorTypes * fix(types, ml-vision): repair invalid `extends` use by duplicating inherited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex * fix(types, perf): add void return types to untyped perf methods * tests(admob): add type override to intentionally-wrong syntax Incorrect type is now caught by TS * tests(types, ml-vision): fix ml-vision test typo, exposed by proper types VisionBarcodeFormat.ALL_POINTS does not exist * chore(website): update typedoc to allow recursive types uses new syntax: TSConfigReader
1 parent 61df91f commit aa8ee8b

File tree

25 files changed

+468
-538
lines changed

25 files changed

+468
-538
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@babel/preset-env": "7.9.5",
4242
"@babel/preset-flow": "7.9.0",
4343
"@types/jest": "^25.2.1",
44+
"@types/react": "^16.9.49",
4445
"@types/react-native": "^0.62.0",
4546
"@typescript-eslint/eslint-plugin": "^2.18.0",
4647
"@typescript-eslint/parser": "^2.18.0",

packages/admob/__tests__/admob.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { firebase } from '../lib';
1+
import { firebase, FirebaseAdMobTypes } from '../lib';
22

33
describe('Admob', () => {
44
describe('namespace', () => {
@@ -21,7 +21,7 @@ describe('Admob', () => {
2121
it('throws if maxAdContentRating is invalid', () => {
2222
expect(() =>
2323
firebase.admob().setRequestConfiguration({
24-
maxAdContentRating: 'Y',
24+
maxAdContentRating: 'Y' as FirebaseAdMobTypes.MaxAdContentRating[keyof FirebaseAdMobTypes.MaxAdContentRating],
2525
}),
2626
).toThrowError(
2727
"firebase.admob().setRequestConfiguration(*) 'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",

packages/admob/lib/index.d.ts

Lines changed: 84 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
1817
import { ReactNativeFirebase } from '@react-native-firebase/app';
18+
import * as React from 'react';
1919

2020
/**
2121
* Firebase Admob package for React Native.
@@ -398,9 +398,9 @@ export namespace FirebaseAdMobTypes {
398398
*/
399399
setDebugGeography(
400400
geography:
401-
| AdsConsentDebugGeography.DISABLED
402-
| AdsConsentDebugGeography.EEA
403-
| AdsConsentDebugGeography.NOT_EEA,
401+
| AdsConsentDebugGeography['DISABLED']
402+
| AdsConsentDebugGeography['EEA']
403+
| AdsConsentDebugGeography['NOT_EEA'],
404404
): Promise<void>;
405405

406406
/**
@@ -424,9 +424,9 @@ export namespace FirebaseAdMobTypes {
424424
*/
425425
setStatus(
426426
status:
427-
| AdsConsentStatus.UNKNOWN
428-
| AdsConsentStatus.NON_PERSONALIZED
429-
| AdsConsentStatus.PERSONALIZED,
427+
| AdsConsentStatus['UNKNOWN']
428+
| AdsConsentStatus['NON_PERSONALIZED']
429+
| AdsConsentStatus['PERSONALIZED'],
430430
): Promise<void>;
431431

432432
/**
@@ -443,7 +443,9 @@ export namespace FirebaseAdMobTypes {
443443
* ```
444444
*/
445445
getStatus(): Promise<
446-
AdsConsentStatus.UNKNOWN | AdsConsentStatus.NON_PERSONALIZED | AdsConsentStatus.PERSONALIZED
446+
| AdsConsentStatus['UNKNOWN']
447+
| AdsConsentStatus['NON_PERSONALIZED']
448+
| AdsConsentStatus['PERSONALIZED']
447449
>;
448450

449451
/**
@@ -537,9 +539,9 @@ export namespace FirebaseAdMobTypes {
537539
* - PERSONALIZED: The user has accepted personalized ads.
538540
*/
539541
status:
540-
| AdsConsentStatus.UNKNOWN
541-
| AdsConsentStatus.NON_PERSONALIZED
542-
| AdsConsentStatus.PERSONALIZED;
542+
| AdsConsentStatus['UNKNOWN']
543+
| AdsConsentStatus['NON_PERSONALIZED']
544+
| AdsConsentStatus['PERSONALIZED'];
543545

544546
/**
545547
* If `true`, the user requested an ad-free version of your application.
@@ -559,9 +561,9 @@ export namespace FirebaseAdMobTypes {
559561
* - PERSONALIZED: The user has accepted personalized ads.
560562
*/
561563
status:
562-
| AdsConsentStatus.UNKNOWN
563-
| AdsConsentStatus.NON_PERSONALIZED
564-
| AdsConsentStatus.PERSONALIZED;
564+
| AdsConsentStatus['UNKNOWN']
565+
| AdsConsentStatus['NON_PERSONALIZED']
566+
| AdsConsentStatus['PERSONALIZED'];
565567

566568
/**
567569
* If `true` the user is within the EEA or their location could not be determined.
@@ -768,10 +770,10 @@ export namespace FirebaseAdMobTypes {
768770
* Ratings are based on the [digital content label classifications](https://support.google.com/admob/answer/7562142).
769771
*/
770772
maxAdContentRating?:
771-
| MaxAdContentRating.G
772-
| MaxAdContentRating.PG
773-
| MaxAdContentRating.T
774-
| MaxAdContentRating.MA;
773+
| MaxAdContentRating['G']
774+
| MaxAdContentRating['PG']
775+
| MaxAdContentRating['T']
776+
| MaxAdContentRating['MA'];
775777

776778
/**
777779
* If `true`, indicates that you want your content treated as child-directed for purposes of COPPA.
@@ -843,14 +845,14 @@ export namespace FirebaseAdMobTypes {
843845
*/
844846
export type AdEventListener = (
845847
type:
846-
| AdEventType.LOADED
847-
| AdEventType.ERROR
848-
| AdEventType.OPENED
849-
| AdEventType.CLICKED
850-
| AdEventType.LEFT_APPLICATION
851-
| AdEventType.CLOSED
852-
| RewardedAdEventType.LOADED
853-
| RewardedAdEventType.EARNED_REWARD,
848+
| AdEventType['LOADED']
849+
| AdEventType['ERROR']
850+
| AdEventType['OPENED']
851+
| AdEventType['CLICKED']
852+
| AdEventType['LEFT_APPLICATION']
853+
| AdEventType['CLOSED']
854+
| RewardedAdEventType['LOADED']
855+
| RewardedAdEventType['EARNED_REWARD'],
854856
error?: Error,
855857
data?: any | RewardedAdReward,
856858
) => void;
@@ -1180,35 +1182,29 @@ export namespace FirebaseAdMobTypes {
11801182
}
11811183
}
11821184

1183-
declare module '@react-native-firebase/admob' {
1184-
// tslint:disable-next-line:no-duplicate-imports required otherwise doesn't work
1185-
import { ReactNativeFirebase } from '@react-native-firebase/app';
1186-
import React from 'react';
1187-
import ReactNativeFirebaseModule = ReactNativeFirebase.Module;
1188-
import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
1189-
import BannerAd = FirebaseAdMobTypes.BannerAd;
1190-
1191-
const firebaseNamedExport: {} & ReactNativeFirebaseModule;
1192-
export const firebase = firebaseNamedExport;
1193-
1194-
export const AdsConsentDebugGeography: {} & FirebaseAdMobTypes.AdsConsentDebugGeography;
1195-
export const AdsConsentStatus: {} & FirebaseAdMobTypes.AdsConsentStatus;
1196-
export const MaxAdContentRating: {} & FirebaseAdMobTypes.MaxAdContentRating;
1197-
export const TestIds: {} & FirebaseAdMobTypes.TestIds;
1198-
export const AdEventType: {} & FirebaseAdMobTypes.AdEventType;
1199-
export const BannerAdSize: {} & FirebaseAdMobTypes.BannerAdSize;
1200-
export const RewardedAdEventType: {} & FirebaseAdMobTypes.RewardedAdEventType;
1201-
export const AdsConsent: {} & FirebaseAdMobTypes.AdsConsent;
1202-
export const InterstitialAd: typeof FirebaseAdMobTypes.InterstitialAd;
1203-
export const RewardedAd: typeof FirebaseAdMobTypes.RewardedAd;
1204-
export const BannerAd: React.SFC<BannerAd>;
1205-
1206-
const defaultExport: FirebaseModuleWithStaticsAndApp<
1207-
FirebaseAdMobTypes.Module,
1208-
FirebaseAdMobTypes.Statics
1209-
>;
1210-
export default defaultExport;
1211-
}
1185+
export const AdsConsentDebugGeography: FirebaseAdMobTypes.AdsConsentDebugGeography;
1186+
export const AdsConsentStatus: FirebaseAdMobTypes.AdsConsentStatus;
1187+
export const MaxAdContentRating: FirebaseAdMobTypes.MaxAdContentRating;
1188+
export const TestIds: FirebaseAdMobTypes.TestIds;
1189+
export const AdEventType: FirebaseAdMobTypes.AdEventType;
1190+
export const BannerAdSize: FirebaseAdMobTypes.BannerAdSize;
1191+
export const RewardedAdEventType: FirebaseAdMobTypes.RewardedAdEventType;
1192+
export const AdsConsent: FirebaseAdMobTypes.AdsConsent;
1193+
export const InterstitialAd: typeof FirebaseAdMobTypes.InterstitialAd;
1194+
export const RewardedAd: typeof FirebaseAdMobTypes.RewardedAd;
1195+
export const BannerAd: React.SFC<FirebaseAdMobTypes.BannerAd>;
1196+
1197+
declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
1198+
FirebaseAdMobTypes.Module,
1199+
FirebaseAdMobTypes.Statics
1200+
>;
1201+
1202+
export const firebase: ReactNativeFirebase.Module & {
1203+
storage: typeof defaultExport;
1204+
app(name?: string): ReactNativeFirebase.FirebaseApp & { admob(): FirebaseAdMobTypes.Module };
1205+
};
1206+
1207+
export default defaultExport;
12121208

12131209
/**
12141210
* Attach namespace to `firebase.` and `FirebaseApp.`.
@@ -1224,41 +1220,39 @@ declare module '@react-native-firebase/app' {
12241220
interface FirebaseApp {
12251221
admob(): FirebaseAdMobTypes.Module;
12261222
}
1227-
}
1228-
}
1229-
1230-
namespace ReactNativeFirebase {
1231-
interface FirebaseJsonConfig {
1232-
/**
1233-
* The Google AdMob application App ID for Android.
1234-
*
1235-
* This can be found under: Apps > App settings > App ID on the Google AdMob dashboard.
1236-
*
1237-
* For testing purposes, use the App ID: `ca-app-pub-3940256099942544~3347511713`.
1238-
*
1239-
* @android
1240-
*/
1241-
admob_android_app_id: string;
12421223

1243-
/**
1244-
* The Google AdMob application App ID for iOS.
1245-
*
1246-
* This can be found under: Apps > App settings > App ID on the Google AdMob dashboard.
1247-
*
1248-
* For testing purposes, use the App ID: `ca-app-pub-3940256099942544~1458002511`.
1249-
*
1250-
* @ios
1251-
*/
1252-
admob_ios_app_id: string;
1253-
1254-
/**
1255-
* By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to
1256-
* Google immediately when the app starts. This initialization behavior ensures you can enable AdMob user metrics
1257-
* without making additional code changes.
1258-
*
1259-
* If you require your app users to provide consent before collecting data, setting the value to `true` will prevent
1260-
* data being sent until the `firebase.admob().initialize()` method has been called.
1261-
*/
1262-
admob_delay_app_measurement_init: boolean;
1224+
interface FirebaseJsonConfig {
1225+
/**
1226+
* The Google AdMob application App ID for Android.
1227+
*
1228+
* This can be found under: Apps > App settings > App ID on the Google AdMob dashboard.
1229+
*
1230+
* For testing purposes, use the App ID: `ca-app-pub-3940256099942544~3347511713`.
1231+
*
1232+
* @android
1233+
*/
1234+
admob_android_app_id: string;
1235+
1236+
/**
1237+
* The Google AdMob application App ID for iOS.
1238+
*
1239+
* This can be found under: Apps > App settings > App ID on the Google AdMob dashboard.
1240+
*
1241+
* For testing purposes, use the App ID: `ca-app-pub-3940256099942544~1458002511`.
1242+
*
1243+
* @ios
1244+
*/
1245+
admob_ios_app_id: string;
1246+
1247+
/**
1248+
* By default, the Google Mobile Ads SDK initializes app measurement and begins sending user-level event data to
1249+
* Google immediately when the app starts. This initialization behavior ensures you can enable AdMob user metrics
1250+
* without making additional code changes.
1251+
*
1252+
* If you require your app users to provide consent before collecting data, setting the value to `true` will prevent
1253+
* data being sent until the `firebase.admob().initialize()` method has been called.
1254+
*/
1255+
admob_delay_app_measurement_init: boolean;
1256+
}
12631257
}
12641258
}

packages/analytics/lib/index.d.ts

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ export namespace FirebaseAnalyticsTypes {
12621262
*
12631263
* @param params See {@link analytics.SetCheckoutOptionEventParameters}.
12641264
*/
1265-
logSetCheckoutOption(params: SetCheckoutOptionEventParameters): Promise<void>;
1265+
logSetCheckoutOption(params: any): Promise<void>;
12661266

12671267
/**
12681268
* Share event. Apps with social features can log the Share event to identify the most viral content.
@@ -1480,21 +1480,19 @@ export namespace FirebaseAnalyticsTypes {
14801480
}
14811481
}
14821482

1483-
declare module '@react-native-firebase/analytics' {
1484-
// tslint:disable-next-line:no-duplicate-imports required otherwise doesn't work
1485-
import { ReactNativeFirebase } from '@react-native-firebase/app';
1486-
import ReactNativeFirebaseModule = ReactNativeFirebase.Module;
1487-
import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics;
1483+
declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics<
1484+
FirebaseAnalyticsTypes.Module,
1485+
FirebaseAnalyticsTypes.Statics
1486+
>;
14881487

1489-
const firebaseNamedExport: {} & ReactNativeFirebaseModule;
1490-
export const firebase = firebaseNamedExport;
1488+
export const firebase: ReactNativeFirebase.Module & {
1489+
analytics: typeof defaultExport;
1490+
app(
1491+
name?: string,
1492+
): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsTypes.Module };
1493+
};
14911494

1492-
const defaultExport: FirebaseModuleWithStatics<
1493-
FirebaseAnalyticsTypes.Module,
1494-
FirebaseAnalyticsTypes.Statics
1495-
>;
1496-
export default defaultExport;
1497-
}
1495+
export default defaultExport;
14981496

14991497
/**
15001498
* Attach namespace to `firebase.` and `FirebaseApp.`.
@@ -1512,33 +1510,31 @@ declare module '@react-native-firebase/app' {
15121510
interface FirebaseApp {
15131511
analytics(): FirebaseAnalyticsTypes.Module;
15141512
}
1515-
}
1516-
}
15171513

1518-
namespace ReactNativeFirebase {
1519-
interface FirebaseJsonConfig {
1520-
/**
1521-
* Disable or enable auto collection of analytics data.
1522-
*
1523-
* This is useful for opt-in-first data flows, for example when dealing with GDPR compliance.
1524-
* This can be overridden in JavaScript.
1525-
*
1526-
* #### Example
1527-
*
1528-
* ```json
1529-
* // <project-root>/firebase.json
1530-
* {
1531-
* "react-native": {
1532-
* "analytics_auto_collection_enabled": false
1533-
* }
1534-
* }
1535-
* ```
1536-
*
1537-
* ```js
1538-
* // Re-enable analytics data collection, e.g. once user has granted permission:
1539-
* await firebase.analytics().setAnalyticsCollectionEnabled(true);
1540-
* ```
1541-
*/
1542-
analytics_auto_collection_enabled: boolean;
1514+
interface FirebaseJsonConfig {
1515+
/**
1516+
* Disable or enable auto collection of analytics data.
1517+
*
1518+
* This is useful for opt-in-first data flows, for example when dealing with GDPR compliance.
1519+
* This can be overridden in JavaScript.
1520+
*
1521+
* #### Example
1522+
*
1523+
* ```json
1524+
* // <project-root>/firebase.json
1525+
* {
1526+
* "react-native": {
1527+
* "analytics_auto_collection_enabled": false
1528+
* }
1529+
* }
1530+
* ```
1531+
*
1532+
* ```js
1533+
* // Re-enable analytics data collection, e.g. once user has granted permission:
1534+
* await firebase.analytics().setAnalyticsCollectionEnabled(true);
1535+
* ```
1536+
*/
1537+
analytics_auto_collection_enabled: boolean;
1538+
}
15431539
}
15441540
}

0 commit comments

Comments
 (0)