FirebaseExtended / FirebaseExtended/reactfire

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

Offen
#741 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
v5
Vorherrschende Sprache
TypeScript
Sterne
3.6k
Forks
403
Ø Merge
14 Std. 53 Min.
Gemergte PRs (30 T.)
5

Beschreibung

## Summary

`ReactFireOptions` 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` |
| `useFirestoreDocOnce` | `DocumentSnapshot` |
| `useFirestoreCollection` | `QuerySnapshot` |

> **Corrected:** this table originally listed a fourth row, `useFirestoreCollectionOnce`. **No such export exists.** The raw snapshot hooks are the three above.

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).

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by locating ReactFireOptions and the raw snapshot hooks useFirestoreDoc, useFirestoreDocOnce, and useFirestoreCollection. Review the known limitation tracked in #740, then compare these types with the data hooks. Done means snapshot hooks accept their DocumentSnapshot or QuerySnapshot initialData types while data hooks retain T, with no runtime changes.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
firebase, react, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.