Skip to content

RTK Query typing .select function #1432

Answered by markerikson
joel-stewart asked this question in Q&A
Discussion options

You must be logged in to vote

As a general observation, TS works best when you infer as much as possible, and that's also true for working with RTK.

Note that the use of ordersSelector there is a bit off, because endpoint.select() actually creates a new selector instance every time. Also, if you have any query args involved here, those need to be passed in as endpoint.select(sameQueryArgsHere) so that it knows which cache entry to retrieve.

I'm pretty sure that if you just do const ordersSelector = ordersService.endpoints.getOrders.select(), this should be typed correctly already.

And sure, contributions are always welcome! :)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@phryneas
Comment options

@joel-stewart
Comment options

@phryneas
Comment options

@joel-stewart
Comment options

Answer selected by joel-stewart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants