You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type of ObservableStatus::data should include undefined #577
Other (e.g. Node, browser, operating system) (if applicable):
Test case
const myDoc = useFirestoreDoc(myRef);
console.log(myDoc.data.data().anyProperty); // <- will throw an error accessing "data.data()" since it
Steps to reproduce
Description
The Firestore access hooks, e.g. useFirestoreDoc(), useFirestoreCollection() etc, all return an ObservableStatus object. The ObservableStatus interface guarantees the presence of data, which is untrue, since it will initially be undefined (unless using suspense).
Currently, ObservableStatus is defined as follows:
exportinterfaceObservableStatus<T>{status: 'loading'|'error'|'success';hasEmitted: boolean;// has received at least one valueisComplete: boolean;data: T;error: Error|undefined;firstValuePromise: Promise<void>;}
Expected behavior
const myDoc = useFirestoreDoc(myRef);
console.log(myDoc.data.data().anyProperty); // <- will throw an error accessing "data.data()" since it
// ^^^^^^^
// Type Error: data may be undefined
I expect the types to indicate that Observable::data is either T | undefined.
Actual behavior
The type system does not warn you when accessing properties on data while it's undefined.
At run time it throws an error attempting to access properties on undefined.
Agree. I've always found the inaccurate types confusing. It leads to error prone code, since the result of these hooks is briefly undefined before they return valid values.
Activity
devth commentedon Jun 3, 2023
Agree. I've always found the inaccurate types confusing. It leads to error prone code, since the result of these hooks is briefly
undefinedbefore they return valid values.webbertakken commentedon Jun 22, 2026
It's on their radar now: #570 (comment)
fix: update useFirestoreDocData return type to include undefined
fix: update useFirestoreDocData return type to include undefined (Fir…
fix: update useFirestoreDocData return type to include undefined (Fir…