Skip to content

Commit 2ee81c2

Browse files
committed
fix: update useFirestoreDocData return type to include undefined
docData() from rxfire returns Observable<T | undefined> because a Firestore document may not exist. The previous ObservableStatus<T> return type was a lie — callers would get undefined at runtime with no type-level warning. Fixes #577
1 parent 28c5ce7 commit 2ee81c2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/firestore.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function useFirestoreDocOnce<T = DocumentData>(ref: DocumentReference<T>,
5959
/**
6060
* Subscribe to Firestore Document changes and unwrap the document into a plain object
6161
*/
62-
export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T> {
62+
export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T | undefined> {
6363
const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
6464

6565
const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;
@@ -71,7 +71,7 @@ export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, opti
7171
/**
7272
* Get a Firestore document, unwrap the document into a plain object, and don't subscribe to changes
7373
*/
74-
export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T> {
74+
export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>, options?: ReactFireOptions<T>): ObservableStatus<T | undefined> {
7575
const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
7676

7777
const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;

0 commit comments

Comments
 (0)