Skip to content

Type of ObservableStatus::data should include undefined #577

Closed

Description

@wmadden

Version info

React:

Firebase:

ReactFire:
4.2.2

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:

export interface ObservableStatus<T> {
  status: 'loading' | 'error' | 'success';
  hasEmitted: boolean; // has received at least one value
  isComplete: 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.

Activity

  1. devth commented on Jun 3, 2023

    @devth

    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.

  2. webbertakken commented on Jun 22, 2026

    @webbertakken
    Contributor

    It's on their radar now: #570 (comment)

  3. added a commit that references this issue on Jul 9, 2026
    2ee81c2
  4. added 2 commits that reference this issue on Jul 15, 2026
    38c8ab7
    7e3b9d2
  5. locked and limited conversation to collaborators on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions