Skip to content

Commit 11efee5

Browse files
authored
fix(types): enable TypeScript libCheck & resolve type conflicts (invertase#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 ef7af2e commit 11efee5

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

lib/index.d.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ export namespace FirebaseMessagingTypes {
608608
* @param authorizedEntity The messaging sender ID. In most cases this will be the current default app.
609609
* @param scope The scope to assign a token, which the sever can use to target messages at.
610610
*/
611-
getToken(authorizedEntity?: string, scope?: string = 'FCM'): Promise<string>;
611+
getToken(authorizedEntity?: string, scope?: string): Promise<string>;
612612

613613
/**
614614
* Removes access to an FCM token previously authorized by it's scope. Messages sent by the server
@@ -623,7 +623,7 @@ export namespace FirebaseMessagingTypes {
623623
* @param authorizedEntity The messaging sender ID. In most cases this will be the current default app.
624624
* @param scope The scope to assign when token will be deleted.
625625
*/
626-
deleteToken(authorizedEntity?: string, scope?: string = 'FCM'): Promise<void>;
626+
deleteToken(authorizedEntity?: string, scope?: string): Promise<void>;
627627

628628
/**
629629
* When any FCM payload is received, the listener callback is called with a `RemoteMessage`.
@@ -897,7 +897,7 @@ export namespace FirebaseMessagingTypes {
897897
* ```
898898
*
899899
*/
900-
setBackgroundMessageHandler(handler: (message: RemoteMessage) => Promise<any>);
900+
setBackgroundMessageHandler(handler: (message: RemoteMessage) => Promise<any>): void;
901901

902902
/**
903903
* Send a new `RemoteMessage` to the FCM server.
@@ -949,21 +949,19 @@ export namespace FirebaseMessagingTypes {
949949
}
950950
}
951951

952-
declare module '@react-native-firebase/messaging' {
953-
// tslint:disable-next-line:no-duplicate-imports required otherwise doesn't work
954-
import { ReactNativeFirebase } from '@react-native-firebase/app';
955-
import ReactNativeFirebaseModule = ReactNativeFirebase.Module;
956-
import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics;
952+
declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics<
953+
FirebaseMessagingTypes.Module,
954+
FirebaseMessagingTypes.Statics
955+
>;
957956

958-
const firebaseNamedExport: {} & ReactNativeFirebaseModule;
959-
export const firebase = firebaseNamedExport;
957+
export const firebase: ReactNativeFirebase.Module & {
958+
messaging: typeof defaultExport;
959+
app(
960+
name?: string,
961+
): ReactNativeFirebase.FirebaseApp & { messaging(): FirebaseMessagingTypes.Module };
962+
};
960963

961-
const defaultExport: FirebaseModuleWithStatics<
962-
FirebaseMessagingTypes.Module,
963-
FirebaseMessagingTypes.Statics
964-
>;
965-
export default defaultExport;
966-
}
964+
export default defaultExport;
967965

968966
/**
969967
* Attach namespace to `firebase.` and `FirebaseApp.`.
@@ -981,23 +979,21 @@ declare module '@react-native-firebase/app' {
981979
interface FirebaseApp {
982980
messaging(): FirebaseMessagingTypes.Module;
983981
}
984-
}
985-
}
986982

987-
namespace ReactNativeFirebase {
988-
interface FirebaseJsonConfig {
989-
messaging_auto_init_enabled?: boolean;
990-
messaging_android_headless_task_timeout?: number;
991-
messaging_android_notification_channel_id?: string;
992-
messaging_android_notification_color?: string;
993-
/**
994-
* Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`
995-
* automatically on app launch (recommended) - defaults to true.
996-
*
997-
* If set to false; make sure to call `firebase.messaging().registerDeviceForRemoteMessages()`
998-
* early on in your app startup - otherwise you will NOT receive remote messages/notifications
999-
* in your app.
1000-
*/
1001-
messaging_ios_auto_register_for_remote_messages?: boolean;
983+
interface FirebaseJsonConfig {
984+
messaging_auto_init_enabled?: boolean;
985+
messaging_android_headless_task_timeout?: number;
986+
messaging_android_notification_channel_id?: string;
987+
messaging_android_notification_color?: string;
988+
/**
989+
* Whether RNFirebase Messaging automatically calls `[[UIApplication sharedApplication] registerForRemoteNotifications];`
990+
* automatically on app launch (recommended) - defaults to true.
991+
*
992+
* If set to false; make sure to call `firebase.messaging().registerDeviceForRemoteMessages()`
993+
* early on in your app startup - otherwise you will NOT receive remote messages/notifications
994+
* in your app.
995+
*/
996+
messaging_ios_auto_register_for_remote_messages?: boolean;
997+
}
1002998
}
1003999
}

0 commit comments

Comments
 (0)