Skip to content

Add type to DocumentReference/CollectionReference/Query #3402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/firestore/exp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export type SetOptions =

export class DocumentReference<T = DocumentData> {
private constructor();
readonly type: 'document';
readonly id: string;
readonly firestore: FirebaseFirestore;
readonly path: string;
Expand Down Expand Up @@ -272,6 +273,7 @@ export type WhereFilterOp =

export class Query<T = DocumentData> {
protected constructor();
readonly type: 'query' | 'collection';
readonly firestore: FirebaseFirestore;
where(
fieldPath: string | FieldPath,
Expand Down Expand Up @@ -320,6 +322,7 @@ export interface DocumentChange<T = DocumentData> {

export class CollectionReference<T = DocumentData> extends Query<T> {
private constructor();
readonly type: 'collection';
readonly id: string;
readonly path: string;
withConverter<U>(
Expand Down
3 changes: 3 additions & 0 deletions packages/firestore/lite/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export type SetOptions =

export class DocumentReference<T = DocumentData> {
private constructor();
readonly type: 'document';
readonly id: string;
readonly firestore: FirebaseFirestore;
readonly path: string;
Expand Down Expand Up @@ -227,6 +228,7 @@ export type WhereFilterOp =

export class Query<T = DocumentData> {
protected constructor();
readonly type: 'query' | 'collection';
readonly firestore: FirebaseFirestore;
where(
fieldPath: string | FieldPath,
Expand Down Expand Up @@ -264,6 +266,7 @@ export class QuerySnapshot<T = DocumentData> {

export class CollectionReference<T = DocumentData> extends Query<T> {
private constructor();
readonly type: 'collection';
readonly id: string;
readonly path: string;
withConverter<U>(
Expand Down
6 changes: 6 additions & 0 deletions packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import { Code, FirestoreError } from '../../../src/util/error';
export class DocumentReference<T = firestore.DocumentData>
extends DocumentKeyReference<T>
implements firestore.DocumentReference<T> {
readonly type = 'document';

constructor(
readonly firestore: Firestore,
key: DocumentKey,
Expand All @@ -99,6 +101,8 @@ export class DocumentReference<T = firestore.DocumentData>

export class Query<T = firestore.DocumentData> extends BaseQuery
implements firestore.Query<T> {
readonly type: 'query' | 'collection' = 'query';

// This is the lite version of the Query class in the main SDK.
constructor(
readonly firestore: Firestore,
Expand Down Expand Up @@ -256,6 +260,8 @@ export class Query<T = firestore.DocumentData> extends BaseQuery

export class CollectionReference<T = firestore.DocumentData> extends Query<T>
implements firestore.CollectionReference<T> {
readonly type = 'collection';

constructor(
readonly firestore: Firestore,
readonly _path: ResourcePath,
Expand Down