Skip to content

fix: update useFirestoreDocData return type to include undefined#733

Merged
tyler-reitz merged 2 commits into
FirebaseExtended:mainfrom
tyler-reitz:fix/observable-status-undefined-type
Jul 9, 2026
Merged

fix: update useFirestoreDocData return type to include undefined#733
tyler-reitz merged 2 commits into
FirebaseExtended:mainfrom
tyler-reitz:fix/observable-status-undefined-type

Conversation

@tyler-reitz

Copy link
Copy Markdown
Contributor

Problem

useFirestoreDocData and useFirestoreDocDataOnce were declared to return ObservableStatus<T>, but docData() from rxfire returns Observable<T | undefined> because a Firestore document may not exist. This meant callers could access data.someProperty without any type-level warning, only to get a runtime error when data was undefined.

Fix

Update the return types to ObservableStatus<T | undefined>, which accurately reflects what the observable emits. The discriminated union in ObservableStatus already handles this correctly — status: 'loading' has data: undefined, status: 'success' has data: T | undefined for these hooks.

TypeScript now correctly flags:

const { data } = useFirestoreDocData(ref);
data.someProperty; // TS18048: 'data' is possibly 'undefined'

// Narrowing works as expected:
if (status === 'success' && data) {
  data.someProperty; // OK
}

Fixes #577

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates type definitions across several files. It replaces JSX.Element with React.ReactElement in auth.tsx, performance.tsx, and storage.tsx, and adds an explicit React.ReactElement return type in sdk.tsx. Additionally, it updates the return types of useFirestoreDocData and useFirestoreDocDataOnce in firestore.tsx to allow undefined values (ObservableStatus<T | undefined>). There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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 FirebaseExtended#577
@tyler-reitz tyler-reitz force-pushed the fix/observable-status-undefined-type branch from 11e645d to 2bdb63a Compare July 9, 2026 21:33
@tyler-reitz tyler-reitz merged commit 38c8ab7 into FirebaseExtended:main Jul 9, 2026
12 checks passed
@tyler-reitz tyler-reitz deleted the fix/observable-status-undefined-type branch July 9, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type of ObservableStatus::data should include undefined

2 participants