kevlened / fireway

A schema migration tool for firestore
MIT License
279 stars 41 forks source link

Typescript: Incorrect type for FieldValue #27

Closed optimistiks closed 3 years ago

optimistiks commented 3 years ago

Imagine you have this (Renamed FieldValue to fv to avoid confusion below).

function migrate({ firestore, FieldValue: fv }: MigrateOptions) {}

So in this case, if you do something like

const timestamp = fv.serverTimestamp()

Typescript will complain: Property serverTimestamp is a static member of type FieldValue.

It's because fv is typed as instance of class FieldValue, not the class FieldValue itself.

The solution would be to type it like this FieldValue: typeof FieldValue.

I haven't checked, but it might be the case for FieldPath and Timestamp as well.

kevlened commented 3 years ago

Excellent. Thanks! I don't use TypeScript in my day-to-day, so any feedback is appreciated.

This is published in fireway@1.0.2