FirebaseExtended / FirebaseExtended/reactfire

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

Đang mở
#741 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
v5
Ngôn ngữ chính
TypeScript
Star
3.6k
Fork
403
Merge trung bình
14 giờ 53 phút
Pull request đã merge (30 ngày)
5

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
firebase, react, typescript
Lĩnh vực
frontend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
52/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.