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
types: initialData in ReactFireOptions<T> should accept snapshot types for snapshot hooks #741
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>
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
Split ReactFireOptions into separate types for data hooks vs snapshot hooks, each with the correct initialData type.
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.
Flagging this as a 5.0.0 release gate, not just a follow-up.
#740 is being retargeted to v5. It removes the | any from initialData, which is the fix #383 asks for and is correct for the data hooks (useFirestoreDocData, useFirestoreCollectionData, useDatabaseObjectData).
For the raw snapshot hooks it is not. useFirestoreDoc / useFirestoreDocOnce / useFirestoreCollection resolve to a DocumentSnapshot<T> / QuerySnapshot<T>, so the correct initialData is a snapshot, but the tightened interface says T:
// compiles on main today, errors once #740 landsuseFirestoreDoc(ref,{initialData: someDocumentSnapshot});
The mismatch is pre-existing; #740 makes it visible by removing the any that hid it. But it means if #740 ships in 5.0.0 and this does not, 5.0.0 releases an interface where correct usage of four hooks does not compile, and the workaround is a cast. That is a worse consumer story than the any we are removing.
They do not need to be the same PR. They do need to be the same release.
Raised originally by @armando-navarro in review on #740 ("should #741 land with this PR so the snapshot hooks never ship demanding the wrong initialData type?"). Recording the answer here: separate PR, both required for 5.0.0.
Activity
tyler-reitz commentedon Aug 3, 2026
Flagging this as a 5.0.0 release gate, not just a follow-up.
#740 is being retargeted to
v5. It removes the| anyfrominitialData, which is the fix #383 asks for and is correct for the data hooks (useFirestoreDocData,useFirestoreCollectionData,useDatabaseObjectData).For the raw snapshot hooks it is not.
useFirestoreDoc/useFirestoreDocOnce/useFirestoreCollectionresolve to aDocumentSnapshot<T>/QuerySnapshot<T>, so the correctinitialDatais a snapshot, but the tightened interface saysT:The mismatch is pre-existing; #740 makes it visible by removing the
anythat hid it. But it means if #740 ships in 5.0.0 and this does not, 5.0.0 releases an interface where correct usage of four hooks does not compile, and the workaround is a cast. That is a worse consumer story than theanywe are removing.They do not need to be the same PR. They do need to be the same release.
Raised originally by @armando-navarro in review on #740 ("should #741 land with this PR so the snapshot hooks never ship demanding the wrong
initialDatatype?"). Recording the answer here: separate PR, both required for 5.0.0.fix: tighten ReactFireOptions generic types, remove T | any widening
fix: tighten ReactFireOptions generic types, remove T | any widening
fix(types): give the snapshot hooks snapshot-typed initialData
fix: tighten ReactFireOptions generic types, remove T | any widening