Skip to content

Types for date fields differ in input and output. #124

@jckw

Description

@jckw

The input type is different to the output type for a date field, however the types in functions etc do not reflect this.

E.g.

type Profile = {
  createdAt: Date
}

const { add, data } = useCollection<Profile>('profiles')


add({
  // works and correctly stored as a timestamp in Firestore
  createdAt: new Date()
})

console.log(data[0].createdAt instance Date) // false
// actually an instance of FirestoreTimestamp

Since the type used is the one passed as a the generic Profile, the type of createdAt in data is wrong.

There is also one exception to this rule: if the cache is being used after add. In that case, there will be two potential types being used... since the cached items that are created via add use the Date types, whereas the cached items from firebase have the FirestoreTimestamp type.

This type mismatch also means that sorting does not work correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions