Type Error: toDate() not found on Timestamp fields in 21.0.0-rc.0
- Dominant language
- TypeScript
- Stars
- 7.8k
- Forks
- 2.2k
- Avg merge
- 22h 28m
- Merged PRs (30d)
- 6
Description
## 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.
Contributor guide
Research direction
Start by reproducing the TypeScript error in the provided docData and DocumentReference example, then trace the Firestore read-operation types around Timestamp, FieldValue, and WithFieldValue. Compare the affected Firebase SDK versions and identify where read results acquire the write-oriented union. Done means the example compiles and Timestamp fields expose toDate() without the FieldValue type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, typescript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100