firebase-admin-node
firebase-admin-node copied to clipboard
[Firestore] Typescript error on date
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.
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.
Solution: import { Timestamp } from "firebase-admin/firestore";
Maybe update the docs?
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.