angular / angular/angularfire

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

Aperta
#3,681 2 commenti 1 reazione 0 assegnatari Vedi su GitHub
comp: firestore comp: typings needs: more info type: bug version: current (v17+)
Lingua principale
TypeScript
Stelle
7.8k
Fork
2.2k
Merge medio
22h 28m
PR unite (30g)
6

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo l'errore TypeScript nell'esempio fornito con docData e DocumentReference, quindi segui i tipi delle operazioni di lettura di Firestore relativi a Timestamp, FieldValue e WithFieldValue. Confronta le versioni interessate del Firebase SDK e individua dove i risultati delle letture acquisiscono l'unione orientata alla scrittura. Il lavoro è completato quando l'esempio viene compilato e i campi Timestamp espongono toDate() senza il tipo FieldValue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
firebase, typescript
Ambito
database
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
65/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.