2
0
mirror of synced 2025-02-18 17:28:24 +00:00

Merge pull request #788 from pheromonez/typescript-definitions-static-module-fix

[typings][Typescript] Fix TS definitions so modules can be accessed from the default export
This commit is contained in:
chrisbianca 2018-01-30 10:41:09 +00:00 committed by GitHub
commit 66da0b9306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

192
lib/index.d.ts vendored
View File

@ -5,99 +5,68 @@
declare module "react-native-firebase" { declare module "react-native-firebase" {
type AuthProvider = { type FirebaseModuleAndStatics<M, S = {}> = {
PROVIDER_ID: string, (): M;
credential: (token: string, secret?: string) => AuthCredential, nativeModuleExists: boolean;
}; } & S
export default class FireBase { // Modules commented-out do not currently have type definitions
constructor(config?: RNFirebase.configurationOptions) export class Firebase {
private constructor();
log: any; // admob: FirebaseModuleAndStatics<RNFirebase.admob.AdMob>;
analytics: FirebaseModuleAndStatics<RNFirebase.Analytics>;
auth: FirebaseModuleAndStatics<RNFirebase.auth.Auth, RNFirebase.auth.AuthStatics>;
// config: FirebaseModule<RNFirebase.config.Config>;
crash: FirebaseModuleAndStatics<RNFirebase.crash.Crash>;
database: FirebaseModuleAndStatics<RNFirebase.database.Database, RNFirebase.database.DatabaseStatics>;
fabric: {
crashlytics: FirebaseModuleAndStatics<RNFirebase.crashlytics.Crashlytics>;
};
firestore: FirebaseModuleAndStatics<RNFirebase.firestore.Firestore, RNFirebase.firestore.FirestoreStatics>;
links: FirebaseModuleAndStatics<RNFirebase.links.Links>;
messaging: FirebaseModuleAndStatics<RNFirebase.messaging.Messaging>;
// perf: FirebaseModuleAndStatics<RNFirebase.perf.Perf>;
storage: FirebaseModuleAndStatics<RNFirebase.storage.Storage>;
// utils: FirebaseModuleAndStatics<RNFirebase.utils.Utils>;
initializeApp(options: Firebase.Options, name: string): App;
app(name?: string): App;
apps(): App[];
SDK_VERSION(): string;
}
namespace Firebase {
interface Options {
apiKey: string;
appId: string;
databaseURL: string;
messagingSenderId: string;
projectId: string;
storageBucket: string;
}
}
const firebase: Firebase;
export default firebase;
// Modules commented-out do not currently have type definitions
export class App {
private constructor();
// admob(): RNFirebase.admob.AdMob;
analytics(): RNFirebase.Analytics; analytics(): RNFirebase.Analytics;
auth(): RNFirebase.auth.Auth;
on(type: string, handler: (msg: any) => void): any; // config(): RNFirebase.config.Config;
database: {
(): RNFirebase.database.Database
ServerValue: {
TIMESTAMP: number
}
};
auth: {
(): RNFirebase.auth.Auth
EmailAuthProvider: AuthProvider,
PhoneAuthProvider: AuthProvider,
GoogleAuthProvider: AuthProvider,
GithubAuthProvider: AuthProvider,
TwitterAuthProvider: AuthProvider,
FacebookAuthProvider: AuthProvider,
PhoneAuthState: {
CODE_SENT: string,
AUTO_VERIFY_TIMEOUT: string,
AUTO_VERIFIED: string,
ERROR: string,
},
};
/**RNFirebase mimics the Web Firebase SDK Storage,
* whilst providing some iOS and Android specific functionality.
*/
storage(): RNFirebase.storage.Storage;
/**
* Firebase Cloud Messaging (FCM) allows you to send push messages at no cost to both Android & iOS platforms.
* Assuming the installation instructions have been followed, FCM is ready to go.
* As the Firebase Web SDK has limited messaging functionality,
* the following methods within react-native-firebase have been created to handle FCM in the React Native environment.
*/
messaging(): RNFirebase.messaging.Messaging;
/**
* RNFirebase provides crash reporting for your app out of the box.
* Please note crashes do not appear in real-time on the console,
* they tend to take a number of hours to appear
* If you want to manually report a crash,
* such as a pre-caught exception this is possible by using the report method.
*/
crash(): RNFirebase.crash.Crash; crash(): RNFirebase.crash.Crash;
database(): RNFirebase.database.Database;
/** fabric: {
* Firebase Dynamic Links are links that work the way you want, on multiple crashlytics(): RNFirebase.crashlytics.Crashlytics,
* platforms, and whether or not your app is already installed.
* See the official Firebase docs:
* https://firebase.google.com/docs/dynamic-links/
*/
links(): RNFirebase.links.Links;
/**
* Cloud Firestore is Firebase's new flagship database solution for mobile
* development, however as at the time of this writing (22 Jan 2018) it is
* still a beta product, and may not be as stable as Firebase Realtime
* Database. Comparison of the two products hers:
* https://firebase.google.com/docs/database/rtdb-vs-firestore
*/
static firestore: {
(): RNFirebase.firestore.Firestore;
} & RNFirebase.firestore.FirestoreStatics;
static fabric: {
crashlytics(): RNFirebase.crashlytics.Crashlytics;
}; };
firestore(): RNFirebase.firestore.Firestore;
apps: Array<string>; links(): RNFirebase.links.Links;
googleApiAvailability: RNFirebase.GoogleApiAvailabilityType; messaging(): RNFirebase.messaging.Messaging;
// perf(): RNFirebase.perf.Performance;
static initializeApp(options?: any | RNFirebase.configurationOptions, name?: string): FireBase; storage(): RNFirebase.storage.Storage;
// utils(): RNFirebase.utils.Utils;
static app(name?: string): FireBase;
[key: string]: any;
} }
namespace RNFirebase { export namespace RNFirebase {
interface RnError extends Error { interface RnError extends Error {
code?: string; code?: string;
} }
@ -495,6 +464,15 @@ declare module "react-native-firebase" {
update(values: Object, onComplete?: (a: RnError | null) => any): Promise<any>; update(values: Object, onComplete?: (a: RnError | null) => any): Promise<any>;
} }
interface DatabaseStatics {
/** @see https://www.firebase.com/docs/java-api/javadoc/com/firebase/client/ServerValue.html#TIMESTAMP */
ServerValue: {
TIMESTAMP: {
[key: string]: string
}
}
}
} }
/** /**
@ -605,7 +583,7 @@ declare module "react-native-firebase" {
* *
* @param forceRefresh: boolean - default to false * @param forceRefresh: boolean - default to false
*/ */
getIdToken(forceRefresh: boolean?): Promise<string> getIdToken(forceRefresh?: boolean): Promise<string>
/** /**
* Link the user with a 3rd party credential provider. * Link the user with a 3rd party credential provider.
@ -722,6 +700,11 @@ declare module "react-native-firebase" {
user: object | null user: object | null
} | null; } | null;
type AuthProvider = {
PROVIDER_ID: string,
credential: (token: string, secret?: string) => AuthCredential,
};
interface Auth { interface Auth {
/** /**
* Returns the current Firebase authentication state. * Returns the current Firebase authentication state.
@ -839,6 +822,21 @@ declare module "react-native-firebase" {
[key: string]: any; [key: string]: any;
} }
interface AuthStatics {
EmailAuthProvider: AuthProvider;
PhoneAuthProvider: AuthProvider;
GoogleAuthProvider: AuthProvider;
GithubAuthProvider: AuthProvider;
TwitterAuthProvider: AuthProvider;
FacebookAuthProvider: AuthProvider;
PhoneAuthState: {
CODE_SENT: string;
AUTO_VERIFY_TIMEOUT: string;
AUTO_VERIFIED: string;
ERROR: string;
};
}
} }
namespace messaging { namespace messaging {
@ -1043,7 +1041,7 @@ declare module "react-native-firebase" {
* Returns an unsubscribe function, call the returned function to * Returns an unsubscribe function, call the returned function to
* unsubscribe from all future events. * unsubscribe from all future events.
*/ */
onLink(listener: (url) => void): () => void; onLink(listener: (url: string) => void): () => void;
} }
/** /**
@ -1098,7 +1096,7 @@ declare module "react-native-firebase" {
FieldValue: typeof FieldValue; FieldValue: typeof FieldValue;
GeoPoint: typeof GeoPoint; GeoPoint: typeof GeoPoint;
enableLogging(enabled: boolean): void; enableLogging(enabled: boolean): void;
}; }
interface CollectionReference { interface CollectionReference {
readonly firestore: Firestore; readonly firestore: Firestore;
@ -1113,7 +1111,7 @@ declare module "react-native-firebase" {
get(): Promise<QuerySnapshot>; get(): Promise<QuerySnapshot>;
limit(limit: number): Query; limit(limit: number): Query;
onSnapshot(onNext: Query.ObserverOnNext, onError?: Query.ObserverOnError): () => void; onSnapshot(onNext: Query.ObserverOnNext, onError?: Query.ObserverOnError): () => void;
onSnapshot(observer: Observer): () => void; onSnapshot(observer: Query.Observer): () => void;
onSnapshot(queryListenOptions: Query.QueryListenOptions, onNext: Query.ObserverOnNext, onError?: Query.ObserverOnError): () => void; onSnapshot(queryListenOptions: Query.QueryListenOptions, onNext: Query.ObserverOnNext, onError?: Query.ObserverOnError): () => void;
onSnapshot(queryListenOptions: Query.QueryListenOptions, observer: Query.Observer): () => void; onSnapshot(queryListenOptions: Query.QueryListenOptions, observer: Query.Observer): () => void;
orderBy(fieldPath: string | FieldPath, directionStr?: Types.QueryDirection): Query; orderBy(fieldPath: string | FieldPath, directionStr?: Types.QueryDirection): Query;
@ -1185,17 +1183,17 @@ declare module "react-native-firebase" {
class GeoPoint { class GeoPoint {
constructor(latitude: number, longitude: number); constructor(latitude: number, longitude: number);
get latitude(): number; readonly latitude: number;
get longitude(): number; readonly longitude: number;
} }
class Path { class Path {
static fromName(name: string): Path; static fromName(name: string): Path;
constructor(pathComponents: string[]); constructor(pathComponents: string[]);
get id(): string | null; readonly id: string | null;
get isDocument(): boolean; readonly isDocument: boolean;
get isCollection(): boolean; readonly isCollection: boolean;
get relativeName(): string; readonly relativeName: string;
child(relativePath: string): Path; child(relativePath: string): Path;
parent(): Path | null; parent(): Path | null;
} }
@ -1272,7 +1270,7 @@ declare module "react-native-firebase" {
readonly metadata: Types.SnapshotMetadata; readonly metadata: Types.SnapshotMetadata;
readonly query: Query; readonly query: Query;
readonly size: number; readonly size: number;
forEach(callback: (snapshot: DocumentSnapshot) => any); forEach(callback: (snapshot: DocumentSnapshot) => any): void;
} }
namespace QuerySnapshot { namespace QuerySnapshot {
interface NativeData { interface NativeData {