firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[Firestore] Typescript error on date

Open electroheadfx opened this issue 3 years ago • 3 comments

My environment

  • Operating System version: macOS Monterey
  • Firebase SDK version: 11.2.0
  • Firebase Product: Firestore
  • Node.js version: v16.17.1
  • NPM version: 8.19.2

Steps to reproduce:

Just request a document with a timestamp, and get the seconds on the object:

data.entryDate.seconds

and I get this typescript error:

Any
Property 'seconds' does not exist on type 'string'.
Translation: You're trying to access seconds on an object that doesn't contain it.

electroheadfx avatar Nov 02 '22 14:11 electroheadfx

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Nov 02 '22 14:11 google-oss-bot

Solution: import { Timestamp } from "firebase-admin/firestore";

Maybe update the docs?

galki avatar Oct 30 '23 21:10 galki

The type definitions mentioned by @galki contain the required readonly properties 'seconds' and 'nanoseconds'. The actual runtime implementation contains the properties '_seconds' and '_nanoseconds'

I had to proxy the type since I have some areas where I validate objects at runtime and it was incorrect.

joshwash avatar Nov 09 '23 22:11 joshwash