Skip to content

Commit c46149a

Browse files
committed
Add exists vs. not interfaces for type guards
1 parent 082fc9a commit c46149a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/firestore/interfaces.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { Subscriber } from 'rxjs';
2-
import { DocumentChangeType, DocumentSnapshot as _DocumentSnapshot, SnapshotOptions, QueryDocumentSnapshot as _QueryDocumentSnapshot, DocumentChange as _DocumentChange, CollectionReference, Query } from '@firebase/firestore-types';
2+
import { DocumentChangeType, FieldPath, DocumentSnapshot as _DocumentSnapshot, SnapshotOptions, QueryDocumentSnapshot as _QueryDocumentSnapshot, DocumentChange as _DocumentChange, CollectionReference, Query } from '@firebase/firestore-types';
33

4-
export interface DocumentSnapshot<T> extends _DocumentSnapshot {
5-
data(options?: SnapshotOptions): T | undefined;
4+
export interface DocumentSnapshotExists<T> extends _DocumentSnapshot {
5+
readonly exists: true;
6+
data(options?: SnapshotOptions): T;
7+
}
8+
9+
export interface DocumentSnapshotDoesNotExist extends _DocumentSnapshot {
10+
readonly exists: false;
11+
data(options?: SnapshotOptions): undefined;
12+
get(fieldPath: string | FieldPath, options?: SnapshotOptions): undefined;
613
}
714

15+
export type DocumentSnapshot<T> = DocumentSnapshotExists<T> | DocumentSnapshotDoesNotExist;
16+
817
export interface QueryDocumentSnapshot<T> extends _QueryDocumentSnapshot {
918
data(options?: SnapshotOptions): T;
1019
}

0 commit comments

Comments
 (0)