Closed skwny closed 3 years ago
Hey, Typesaurus convert dates to timestamp and vise versa, so you can always use native Date
:
import { value, collection, get, set } from 'typesaurus'
interface Thing {
created_on: Date
}
const things = collection<Thing>('things')
await set(things, 'qwe', {
created_on: value('serverDate') // or new Date()
})
const thing = await get(things, 'qwe')
thing.data.created_on.getFullYear()
// => 2021
When retrieving data via
all(collection)
, what should be a Firestore timestamp is actually a Date object. This is unexpected as my schema is a Timestamp, and expects it to have all the associated methods when it comes out of firestore.For example, the following is my schema:
And while saving data:
And when retrieving and using the data:
The above errors because
thing
is actually Date object, not a Firestore Timestamp.Did I miss this in the documentation somewhere? Is this supposed to be how it works?