FirebaseExtended / FirebaseExtended/reactfire
types: initialData in ReactFireOptions<T> should accept snapshot types for snapshot hooks
- 主要语言
- TypeScript
- 星标
- 3.6k
- 派生
- 403
- 平均合并
- 14 小时 53 分钟
- 30 天内合并 PR
- 5
描述
## 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).
贡献指南
调研方向
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.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- firebase, react, typescript
- 领域
- frontend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100