Skip to content

types: initialData in ReactFireOptions<T> should accept snapshot types for snapshot hooks #741

Description

@tyler-reitz

Summary

ReactFireOptions<T> types initialData as T, which is correct for the data hooks (useFirestoreDocData, useFirestoreCollectionData, useDatabaseObjectData, etc.). For the raw snapshot hooks, the correct type is the snapshot wrapper, not the unwrapped data type:

Hook Correct initialData type
useFirestoreDoc DocumentSnapshot<T>
useFirestoreDocOnce DocumentSnapshot<T>
useFirestoreCollection QuerySnapshot<T>
useFirestoreCollectionOnce QuerySnapshot<T>

This mismatch is pre-existing and was silently masked by the T | any widening removed in #740. It is not a regression from that PR.

Options

  1. Split ReactFireOptions into separate types for data hooks vs snapshot hooks, each with the correct initialData type.
  2. Make initialData generic at the hook level (e.g., initialData?: TSnapshot) independent of the data type T.

Either approach would be a TypeScript-only change with no runtime impact.

Tracked in #740 (known limitation section).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions