Skip to content

Commit

Permalink
fix: change typings for select() to return Query<DocumentData> (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Sep 22, 2020
1 parent 20b1226 commit b678857
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,9 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
* console.log(`y is ${res.docs[0].get('y')}.`);
* });
*/
select(...fieldPaths: Array<string | FieldPath>): Query<T> {
select(
...fieldPaths: Array<string | FieldPath>
): Query<firestore.DocumentData> {
const fields: api.StructuredQuery.IFieldReference[] = [];

if (fieldPaths.length === 0) {
Expand All @@ -1304,7 +1306,11 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
}
}

const options = this._queryOptions.with({projection: {fields}});
// By specifying a field mask, the query result no longer conforms to type
// `T`. We there return `Query<DocumentData>`;
const options = this._queryOptions.with({
projection: {fields},
}) as QueryOptions<firestore.DocumentData>;
return new Query(this._firestore, options);
}

Expand Down
2 changes: 1 addition & 1 deletion types/firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ declare namespace FirebaseFirestore {
* @param field The field paths to return.
* @return The created Query.
*/
select(...field: (string | FieldPath)[]): Query<T>;
select(...field: (string | FieldPath)[]): Query<DocumentData>;

/**
* Creates and returns a new Query that starts at the provided document
Expand Down

0 comments on commit b678857

Please sign in to comment.