diff --git a/lib/modules/firestore/CollectionReference.js b/lib/modules/firestore/CollectionReference.js index 7b0794bf..87598b57 100644 --- a/lib/modules/firestore/CollectionReference.js +++ b/lib/modules/firestore/CollectionReference.js @@ -6,9 +6,11 @@ import DocumentReference from './DocumentReference'; import Query from './Query'; import { firestoreAutoId } from '../../utils'; +import type DocumentSnapshot from './DocumentSnapshot'; import type Firestore from './'; import type { FirestoreQueryDirection, FirestoreQueryOperator } from '../../types'; import type Path from './Path'; +import type { Observer, QueryListenOptions } from './Query'; import type QuerySnapshot from './QuerySnapshot'; /** @@ -19,13 +21,13 @@ export default class CollectionReference { _firestore: Firestore; _query: Query; - constructor(firestore: Object, collectionPath: Path) { + constructor(firestore: Firestore, collectionPath: Path) { this._collectionPath = collectionPath; this._firestore = firestore; this._query = new Query(firestore, collectionPath); } - get firestore(): Object { + get firestore(): Firestore { return this._firestore; } @@ -56,36 +58,40 @@ export default class CollectionReference { } // From Query - endAt(fieldValues: any): Query { - return this._query.endAt(fieldValues); + endAt(...snapshotOrVarArgs: any[]): Query { + return this._query.endAt(snapshotOrVarArgs); } - endBefore(fieldValues: any): Query { - return this._query.endBefore(fieldValues); + endBefore(...snapshotOrVarArgs: any[]): Query { + return this._query.endBefore(snapshotOrVarArgs); } get(): Promise { return this._query.get(); } - limit(n: number): Query { - return this._query.limit(n); + limit(limit: number): Query { + return this._query.limit(limit); } - onSnapshot(onNext: () => any, onError?: () => any): () => void { - return this._query.onSnapshot(onNext, onError); + onSnapshot( + optionsOrObserverOrOnNext: QueryListenOptions | Observer | (DocumentSnapshot) => void, + observerOrOnNextOrOnError?: Observer | (DocumentSnapshot) => void | (Object) => void, + onError?: (Object) => void, + ): () => void { + return this._query.onSnapshot(optionsOrObserverOrOnNext, observerOrOnNextOrOnError, onError); } orderBy(fieldPath: string, directionStr?: FirestoreQueryDirection): Query { return this._query.orderBy(fieldPath, directionStr); } - startAfter(fieldValues: any): Query { - return this._query.startAfter(fieldValues); + startAfter(...snapshotOrVarArgs: any[]): Query { + return this._query.startAfter(snapshotOrVarArgs); } - startAt(fieldValues: any): Query { - return this._query.startAt(fieldValues); + startAt(...snapshotOrVarArgs: any[]): Query { + return this._query.startAt(snapshotOrVarArgs); } where(fieldPath: string, opStr: FirestoreQueryOperator, value: any): Query { diff --git a/lib/modules/firestore/DocumentReference.js b/lib/modules/firestore/DocumentReference.js index b47c88c6..97d7c4ae 100644 --- a/lib/modules/firestore/DocumentReference.js +++ b/lib/modules/firestore/DocumentReference.js @@ -163,7 +163,7 @@ export default class DocumentReference { .documentSet(this.path, nativeData, writeOptions); } - update(...args: Array): Promise { + update(...args: any[]): Promise { let data = {}; if (args.length === 1) { if (!isObject(args[0])) { diff --git a/lib/modules/firestore/Query.js b/lib/modules/firestore/Query.js index 507399ff..af11cae4 100644 --- a/lib/modules/firestore/Query.js +++ b/lib/modules/firestore/Query.js @@ -45,12 +45,13 @@ type QueryOptions = { startAfter?: any[], startAt?: any[], } -type QueryListenOptions = { + +export type QueryListenOptions = { includeDocumentMetadataChanges: boolean, includeQueryMetadataChanges: boolean, } -type Observer = { +export type Observer = { next: (DocumentSnapshot) => void, error?: (Object) => void, } @@ -81,7 +82,7 @@ export default class Query { this._referencePath = path; } - get firestore(): Object { + get firestore(): Firestore { return this._firestore; }