Type Error: toDate() not found on Timestamp fields in 21.0.0-rc.0
- Vorherrschende Sprache
- TypeScript
- Sterne
- 7.8k
- Forks
- 2.2k
- Ø Merge
- 22 Std. 28 Min.
- Gemergte PRs (30 T.)
- 6
Beschreibung
## 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.
Beitragsleitfaden
Rechercherichtung
Beginne damit, den TypeScript-Fehler im bereitgestellten Beispiel mit docData und DocumentReference zu reproduzieren, und verfolge dann die Typen der Firestore-Leseoperationen rund um Timestamp, FieldValue und WithFieldValue. Vergleiche die betroffenen Firebase SDK-Versionen und ermittle, an welcher Stelle die Leseergebnisse die schreiborientierte Union erhalten. Als abgeschlossen gilt die Aufgabe, wenn das Beispiel kompiliert und Timestamp-Felder toDate() ohne den FieldValue-Typ bereitstellen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- firebase, typescript
- Bereich
- database
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 65/100