FirebaseExtended / FirebaseExtended/reactfire
types: initialData in ReactFireOptions<T> should accept snapshot types for snapshot hooks
- 主要言語
- TypeScript
- スター
- 3.6k
- フォーク
- 403
- 平均マージ
- 14時間 53分
- マージ済み PR(30日)
- 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