react-redux-firebase
react-redux-firebase copied to clipboard
orderBy in "useFirestoreConnect" config object gives a typescript type error
Hiho,
working much lately with this awesome library.
I encountered another Typescript type related issue:
If you use the useFirestoreConnect
hook like this:
useFirestoreConnect({
collection: "chatRooms/89VzMHrNFHlXEl9uLRWT/chats",
storeAs: "chats",
orderBy: "timestamp",
});
you will get this warning:
Argument of type '{ collection: string; storeAs: string; orderBy: string; }' is not assignable to parameter of type 'string | ReduxFirestoreQuerySetting | ReduxFirestoreQuerySetting[] | string[] | mapper<unknown, (string | ReduxFirestoreQuerySetting)[]> | mapper<...> | undefined'. Types of property 'orderBy' are incompatible. Type 'string' is not assignable to type 'OrderByOptions | OrderByOptions[] | undefined'.ts(2345)
It happens after I added this prop orderBy: "timestamp"
According to the docs over here:
https://github.com/prescottprue/redux-firestore#query-options
I use it fine, but I get this warning. In the types definition I found it at line 380 / 381:
type WhereOptions = [string, FirestoreTypes.WhereFilterOp, any]
type OrderByOptions = [string, FirestoreTypes.OrderByDirection]
Where works fine because of any
I think. Maybe also add any
to the type "OrderByOptions"?
What you think?
Did you try providing an array? I.e. orderBy: ['timestamp']
? The array represents the two arguments being passed to orderBy
Either way, we should update the types to support both since I believe the Firebase SDK supports passing just one
Just faced this issue, moving to orderBy: ['createdAt', 'asc'],
to match the OrderByOptions
was enough.