How do I implement firebase's Timestamp as a valid type?

Viewed 1324

ts/ io-ts and am trying to implement Firebase.Timestamp as a valid type. But I keep getting errors. I can create a normal copy of the time stamp:

copyTimeStamp = {
  seconds : t.number,
  nanoseconds : t.number
}

but if I push that onto firebase using the custom encoded type from io-ts, it isn't stored as Timestamp property rather its just a plain map..

1 Answers

If you want to write a timestamp type field in Firestore, you must use either the native JavaScript Date object, or the Timestamp object provided by the Firestore SDK. You can't simulate it using your own object.

Related