Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Type Error: toDate() not found on Timestamp fields in 21.0.0-rc.0

Đang mở
#3,681 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

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

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.

Mô tả

comp: firestore comp: typings needs: more info type: bug version: current (v17+)

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<Timestamp>'.
  Property 'toDate' does not exist on type 'FieldValue'.

Reproduction

import { doc, docData, Timestamp } from '@angular/fire/firestore';

interface Member {
  createdAt: Timestamp;
}

const member$ = docData(doc(firestore, 'members/123') as DocumentReference<Member>);

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<Timestamp> 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.

Ngôn ngữ chính
TypeScript
Star
7.8k
Fork
2.2k
Merge trung bình
3 ngày 6 giờ
Pull request đã merge (30 ngày)
5

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

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angularfire

Tất cả issue của angular/angularfire

Issue tương tự

Thêm issue về TypeScript

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.