Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run prettier on index.d.ts & Add auth listener callback type #1689

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
128 changes: 80 additions & 48 deletions src/index.d.ts
Expand Up @@ -18,24 +18,40 @@ declare module 'react-native-firebase' {

// type AdmobModule = FirebaseModuleAndStatics<RNFirebase.admob.AdMob>;
type AnalyticsModule = FirebaseModuleAndStatics<RNFirebase.Analytics>;
type AuthModule = FirebaseModuleAndStatics<RNFirebase.auth.Auth,
RNFirebase.auth.AuthStatics>;
type AuthModule = FirebaseModuleAndStatics<
RNFirebase.auth.Auth,
RNFirebase.auth.AuthStatics
>;
type ConfigModule = FirebaseModuleAndStatics<RNFirebase.config.Config>;
type CrashlyticsModule = FirebaseModuleAndStatics<RNFirebase.crashlytics.Crashlytics>;
type DatabaseModule = FirebaseModuleAndStatics<RNFirebase.database.Database,
RNFirebase.database.DatabaseStatics>;
type FirestoreModule = FirebaseModuleAndStatics<RNFirebase.firestore.Firestore,
RNFirebase.firestore.FirestoreStatics>;
type FunctionsModule = FirebaseModuleAndStatics<RNFirebase.functions.Functions,
RNFirebase.functions.FunctionsStatics>;
type CrashlyticsModule = FirebaseModuleAndStatics<
RNFirebase.crashlytics.Crashlytics
>;
type DatabaseModule = FirebaseModuleAndStatics<
RNFirebase.database.Database,
RNFirebase.database.DatabaseStatics
>;
type FirestoreModule = FirebaseModuleAndStatics<
RNFirebase.firestore.Firestore,
RNFirebase.firestore.FirestoreStatics
>;
type FunctionsModule = FirebaseModuleAndStatics<
RNFirebase.functions.Functions,
RNFirebase.functions.FunctionsStatics
>;
type IidModule = FirebaseModuleAndStatics<RNFirebase.iid.InstanceId>;
// type InvitesModule = FirebaseModuleAndStatics<RNFirebase.invites.Invites>;
type LinksModule = FirebaseModuleAndStatics<RNFirebase.links.Links,
RNFirebase.links.LinksStatics>;
type MessagingModule = FirebaseModuleAndStatics<RNFirebase.messaging.Messaging,
RNFirebase.messaging.MessagingStatics>;
type NotificationsModule = FirebaseModuleAndStatics<RNFirebase.notifications.Notifications,
RNFirebase.notifications.NotificationsStatics>;
type LinksModule = FirebaseModuleAndStatics<
RNFirebase.links.Links,
RNFirebase.links.LinksStatics
>;
type MessagingModule = FirebaseModuleAndStatics<
RNFirebase.messaging.Messaging,
RNFirebase.messaging.MessagingStatics
>;
type NotificationsModule = FirebaseModuleAndStatics<
RNFirebase.notifications.Notifications,
RNFirebase.notifications.NotificationsStatics
>;
type PerfModule = FirebaseModuleAndStatics<RNFirebase.perf.Perf>;
type StorageModule = FirebaseModuleAndStatics<RNFirebase.storage.Storage>;
// type UtilsModule: FirebaseModuleAndStatics<RNFirebase.utils.Utils>;
Expand Down Expand Up @@ -561,8 +577,8 @@ declare module 'react-native-firebase' {
exists(): boolean;

exportVal(): {
'.value': any,
'.priority': string | number | null,
'.value': any;
'.priority': string | number | null;
};

forEach(action: (a: database.DataSnapshot) => boolean): boolean;
Expand All @@ -584,11 +600,9 @@ declare module 'react-native-firebase' {
val(): any;
}

interface ThenableReference<T> extends Promise<T> {
}
interface ThenableReference<T> extends Promise<T> {}

interface ThenableReference<T> extends Reference {
}
interface ThenableReference<T> extends Reference {}

interface Reference extends database.Query {
child(path: string): database.Reference;
Expand Down Expand Up @@ -823,7 +837,9 @@ declare module 'react-native-firebase' {
/**
* Re-authenticate a user with a third-party authentication provider
*/
reauthenticateWithCredential(credential: AuthCredential): Promise<UserCredential>;
reauthenticateWithCredential(
credential: AuthCredential
): Promise<UserCredential>;

/**
* Refreshes the current user.
Expand Down Expand Up @@ -888,7 +904,12 @@ declare module 'react-native-firebase' {
email?: string;
fromEmail?: string;
};
operation: 'PASSWORD_RESET' | 'VERIFY_EMAIL' | 'RECOVER_EMAIL' | 'EMAIL_SIGNIN' | 'ERROR';
operation:
| 'PASSWORD_RESET'
| 'VERIFY_EMAIL'
| 'RECOVER_EMAIL'
| 'EMAIL_SIGNIN'
| 'ERROR';
}

interface ConfirmationResult {
Expand Down Expand Up @@ -972,22 +993,23 @@ declare module 'react-native-firebase' {
smsCode: string
): Promise<null>;
}

type OrNull<T> = T | null;
type AuthListenerCallback = (user: OrNull<User>) => void;
interface Auth {
readonly app: App;
/**
* Returns the current Firebase authentication state.
*/
authResult: AuthResult | null;
authResult: OrNull<AuthResult>;
/**
* Returns the currently signed-in user (or null). See the User class documentation for further usage.
*/
currentUser: User | null;
currentUser: OrNull<User>;

/**
* Gets/Sets the language for the app instance
*/
languageCode: string | null;
languageCode: OrNull<string>;

settings: AuthSettings;

Expand All @@ -996,21 +1018,21 @@ declare module 'react-native-firebase' {
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onAuthStateChanged(listener: Function): () => void;
onAuthStateChanged(listener: AuthListenerCallback): () => void;

/**
* Listen for changes in id token.
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onIdTokenChanged(listener: Function): () => void;
onIdTokenChanged(listener: AuthListenerCallback): () => void;

/**
* Listen for changes in the user.
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onUserChanged(listener: Function): () => void;
onUserChanged(listener: AuthListenerCallback): () => void;

signOut(): Promise<void>;

Expand Down Expand Up @@ -1098,7 +1120,9 @@ declare module 'react-native-firebase' {
* Sign in the user with a 3rd party credential provider.
* credential requires the following properties:
*/
signInWithCredential(credential: AuthCredential): Promise<UserCredential>;
signInWithCredential(
credential: AuthCredential
): Promise<UserCredential>;

/**
* Asynchronously signs in using a phone number.
Expand Down Expand Up @@ -1985,7 +2009,10 @@ declare module 'react-native-firebase' {
createDynamicLink(dynamicLink: DynamicLink): Promise<string>;

/** Creates a short dynamic link. */
createShortDynamicLink(dynamicLink: DynamicLink, type: 'SHORT' | 'UNGUESSABLE'): Promise<string>;
createShortDynamicLink(
dynamicLink: DynamicLink,
type: 'SHORT' | 'UNGUESSABLE'
): Promise<string>;

/**
* Returns the URL that the app has been launched from. If the app was
Expand Down Expand Up @@ -2726,7 +2753,14 @@ declare module 'react-native-firebase' {
}

type QueryDirection = 'asc' | 'ASC' | 'desc' | 'DESC';
type QueryOperator = '=' | '==' | '>' | '>=' | '<' | '<=' | 'array-contains';
type QueryOperator =
| '='
| '=='
| '>'
| '>='
| '<'
| '<='
| 'array-contains';

interface TypeMap {
type:
Expand Down Expand Up @@ -2760,7 +2794,7 @@ declare module 'react-native-firebase' {
}

declare module 'react-native-firebase/storage' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Storage = RNFirebase.storage.Storage;
export type Reference = RNFirebase.storage.Reference;
export type FullMetadata = RNFirebase.storage.FullMetadata;
Expand All @@ -2773,7 +2807,7 @@ declare module 'react-native-firebase/storage' {
}

declare module 'react-native-firebase/database' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Database = RNFirebase.database.Database;
export type RnReference = RNFirebase.database.RnReference;
export type QueryEventType = RNFirebase.database.QueryEventType;
Expand All @@ -2784,34 +2818,32 @@ declare module 'react-native-firebase/database' {
export type Reference = RNFirebase.database.Reference;
export type DatabaseStatics = RNFirebase.database.DatabaseStatics;

interface ThenableReference<T> extends Promise<T> {
}
interface ThenableReference<T> extends Promise<T> {}

interface ThenableReference<T> extends RNFirebase.database.Reference {
}
interface ThenableReference<T> extends RNFirebase.database.Reference {}
}

declare module 'react-native-firebase/auth' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type AuthResult = RNFirebase.auth.AuthResult;
export type AuthProvider = RNFirebase.auth.AuthProvider;
export type Auth = RNFirebase.auth.Auth;
export type AuthStatics = RNFirebase.auth.AuthStatics;
}

declare module 'react-native-firebase/messaging' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Messaging = RNFirebase.messaging.Messaging;
export type RemoteMessage = RNFirebase.messaging.RemoteMessage;
}

declare module 'react-native-firebase/iid' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type InstanceId = RNFirebase.iid.InstanceId;
}

declare module 'react-native-firebase/notifications' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type AndroidNotifications = RNFirebase.notifications.AndroidNotifications;
export type Notifications = RNFirebase.notifications.Notifications;
export type Notification = RNFirebase.notifications.Notification;
Expand All @@ -2823,18 +2855,18 @@ declare module 'react-native-firebase/notifications' {
}

declare module 'react-native-firebase/config' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type ConfigSnapshot = RNFirebase.config.ConfigSnapshot;
export type Config = RNFirebase.config.Config;
}

declare module 'react-native-firebase/crashlytics' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Crashlytics = RNFirebase.crashlytics.Crashlytics;
}

declare module 'react-native-firebase/links' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Links = RNFirebase.links.Links;
export type DynamicLink = RNFirebase.links.DynamicLink;
export type AnalyticsParameters = RNFirebase.links.AnalyticsParameters;
Expand All @@ -2846,7 +2878,7 @@ declare module 'react-native-firebase/links' {
}

declare module 'react-native-firebase/functions' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type HttpsErrorCode = RNFirebase.functions.HttpsErrorCode;
export type FunctionsErrorCode = RNFirebase.functions.FunctionsErrorCode;
export type HttpsCallableResult = RNFirebase.functions.HttpsCallableResult;
Expand All @@ -2855,7 +2887,7 @@ declare module 'react-native-firebase/functions' {
}

declare module 'react-native-firebase/firestore' {
import {RNFirebase} from 'react-native-firebase';
import { RNFirebase } from 'react-native-firebase';
export type Firestore = RNFirebase.firestore.Firestore;
export type FirestoreStatics = RNFirebase.firestore.FirestoreStatics;
export type CollectionReference = RNFirebase.firestore.CollectionReference;
Expand Down