Skip to content

Commit 07f2dff

Browse files
authored
Make GeoFireCollectionRef generic
This adds the possibility to supply a type to the reference, which improves the compiler hints when accessing properties
1 parent b2afd48 commit 07f2dff

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/collection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ export interface QueryMetadata {
1919
}
2020

2121
export interface GeoQueryDocument {
22-
[key: string]: any;
2322
queryMetadata: QueryMetadata;
2423
}
2524

26-
export class GeoFireCollectionRef {
25+
export class GeoFireCollectionRef<T> {
2726
private ref: firestore.CollectionReference;
2827
private query: firestore.Query;
2928
private stream: Observable<firestore.QuerySnapshot>;
@@ -120,7 +119,7 @@ export class GeoFireCollectionRef {
120119
radius: number,
121120
field: string,
122121
opts = defaultOpts
123-
): Observable<GeoQueryDocument[]> {
122+
): Observable<(GeoQueryDocument & T)[]> {
124123
const precision = setPrecsion(radius);
125124
const centerHash = center.hash.substr(0, precision);
126125
const area = GeoFirePoint.neighbors(centerHash).concat(centerHash);
@@ -147,7 +146,7 @@ export class GeoFireCollectionRef {
147146
distance: center.distance(lat, lng),
148147
bearing: center.bearing(lat, lng)
149148
};
150-
return { ...val, queryMetadata };
149+
return { ...val, queryMetadata } as (GeoQueryDocument & T);
151150
})
152151

153152
.sort((a, b) => a.queryMetadata.distance - b.queryMetadata.distance);

0 commit comments

Comments
 (0)