From 46c7d03c8a3f3c42689618a9ee5317ad64d88458 Mon Sep 17 00:00:00 2001 From: Levi Botelho Date: Mon, 18 Sep 2017 09:23:34 +0200 Subject: [PATCH] Update database TypeScript types --- index.d.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2041bafe..2b940bae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -307,22 +307,27 @@ declare module "react-native-firebase" { [key: string]: any; } + type QueryEventType = "value" | "child_added" | "child_removed" | "child_changed" | "child_moved"; + type QuerySuccessCallback = (snapshot: DataSnapshot, previousChildId?: string | null) => void; + type QueryErrorCallback = (e: Error) => void; + interface Query { endAt(value: number | string | boolean | null, key?: string): database.Query; equalTo(value: number | string | boolean | null, key?: string): database.Query; isEqual(other: database.Query | null): boolean; limitToFirst(limit: number): database.Query; limitToLast(limit: number): database.Query; - off(eventType?: string, - callback?: (a: database.DataSnapshot, b?: string | null) => any, - context?: Object | null): any; - on(eventType: string, - callback: (a: database.DataSnapshot | null, b?: string) => any, - cancelCallbackOrContext?: Object | null, context?: Object | null): (a: database.DataSnapshot | null, b?: string) => any; - once(eventType: string, - successCallback?: (a: database.DataSnapshot, b?: string) => any, - failureCallbackOrContext?: Object | null, - context?: Object | null): Promise; + off(eventType?: QueryEventType, + callback?: QuerySuccessCallback, + context?: Object): void; + on(eventType: QueryEventType, + callback: QuerySuccessCallback, + cancelCallbackOrContext?: QueryErrorCallback, + context?: Object): (a: database.DataSnapshot | null, b?: string) => QuerySuccessCallback; + once(eventType: QueryEventType, + successCallback?: QuerySuccessCallback, + failureCallbackOrContext?: QueryErrorCallback, + context?: Object): Promise; orderByChild(path: string): database.Query; orderByKey(): database.Query; orderByPriority(): database.Query; @@ -348,12 +353,15 @@ declare module "react-native-firebase" { val(): any; } + interface ThenableReference extends Promise {} + interface ThenableReference extends Reference {} + interface Reference extends database.Query { child(path: string): database.Reference; key: string | null; onDisconnect(): any; parent: database.Reference | null; - push(value?: any, onComplete?: (a: RnError | null) => any): any + push(value?: any, onComplete?: (a: RnError | null) => any): ThenableReference remove(onComplete?: (a: RnError | null) => any): Promise; root: database.Reference; set(value: any, onComplete?: (a: RnError | null) => any): Promise;