Type Error: toDate() not found on Timestamp fields in 21.0.0-rc.0
- Ngôn ngữ chính
- TypeScript
- Star
- 7.8k
- Fork
- 2.2k
- Merge trung bình
- 22 giờ 28 phút
- Pull request đã merge (30 ngày)
- 6
Mô tả
## Issue
After upgrading to `@angular/fire@21.0.0-rc.0`, TypeScript compilation fails when calling `.toDate()` on `Timestamp` fields from Firestore documents.
## Error
```
TS2339: Property 'toDate' does not exist on type 'FieldValue | WithFieldValue'.
Property 'toDate' does not exist on type 'FieldValue'.
```
## Reproduction
```typescript
import { doc, docData, Timestamp } from '@angular/fire/firestore';
interface Member {
createdAt: Timestamp;
}
const member$ = docData(doc(firestore, 'members/123') as DocumentReference);
member$.subscribe((member) => {
// ERROR: Property 'toDate' does not exist
const date = member?.createdAt.toDate();
});
```
## Environment
- @angular/fire: 21.0.0-rc.0
- @angular/core: 21.0.1
- firebase: 12.6.0 (from 11.8.0)
- TypeScript: 5.9.3
## Analysis
`Timestamp` fields are being typed as `FieldValue | WithFieldValue` instead of just `Timestamp`. The `WithFieldValue` type (meant for writes) is incorrectly being applied to read operations, causing TypeScript to think the field could be `FieldValue`, which doesn't have `.toDate()`.
This appears to be a regression from the Firebase SDK v11→v12 upgrade in this RC.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện lỗi TypeScript trong ví dụ được cung cấp với docData và DocumentReference, sau đó lần theo các kiểu của thao tác đọc Firestore xung quanh Timestamp, FieldValue và WithFieldValue. So sánh các phiên bản Firebase SDK bị ảnh hưởng và xác định nơi kết quả đọc nhận được union định hướng ghi. Hoàn tất khi ví dụ biên dịch được và các trường Timestamp cung cấp toDate() mà không có kiểu FieldValue.
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, typescript
- Lĩnh vực
- database
- 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
- 65/100