react-redux-firebase icon indicating copy to clipboard operation
react-redux-firebase copied to clipboard

orderBy in "useFirestoreConnect" config object gives a typescript type error

Open dhuber666 opened this issue 4 years ago • 2 comments

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?

dhuber666 avatar Apr 24 '20 10:04 dhuber666

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

prescottprue avatar Apr 27 '20 01:04 prescottprue

Just faced this issue, moving to orderBy: ['createdAt', 'asc'], to match the OrderByOptions was enough.

cabello avatar Feb 10 '22 19:02 cabello