angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

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

Open markgoho opened this issue 2 months ago • 1 comments

Issue

After upgrading to @angular/[email protected], 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.

markgoho avatar Nov 26 '25 14:11 markgoho

Thanks for giving the RC a spin @markgoho

jamesdaniels avatar Nov 26 '25 18:11 jamesdaniels