Type Error: toDate() not found on Timestamp fields in 21.0.0-rc.0
- Lenguaje dominante
- TypeScript
- Estrellas
- 7.8k
- Forks
- 2.2k
- Merge medio
- 22 h 28 min
- PR fusionados (30 d)
- 6
Descripción
## 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.
Guía de contribución
Línea de trabajo
Comienza reproduciendo el error de TypeScript en el ejemplo proporcionado con docData y DocumentReference, y luego rastrea los tipos de las operaciones de lectura de Firestore en torno a Timestamp, FieldValue y WithFieldValue. Compara las versiones afectadas del Firebase SDK e identifica dónde los resultados de lectura adquieren la unión orientada a escritura. Se considera terminado cuando el ejemplo compila y los campos Timestamp exponen toDate() sin el tipo FieldValue.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- firebase, typescript
- Área
- database
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 65/100