Skip to content

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

@markgoho

Description

@markgoho

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions