-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having generic type for BaseQueryAPI #1685
Comments
Hey, thanks for the suggestion & PR! To be honest, unless we get the feedback a lot that this is needed, I'd prefer to keep it like it is at the moment and have people write a type assertion in BaseQuery like const baseQuery: BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta> = async (arg, api) => {
+ const getState = api.getState as () => MyState;
+ const extra = api.extra as Something
} I think this is not a very common use case and as long as TS Generic arguments are still positional and not named, each and every one we add makes using the whole type more weird to use, makes maintenance more difficult and locks us into certain decisions we might regret later down the path. |
I totally understand your point of view, We do not have a way to have the generic type, and if it's not provided still keep the current default one without complexity the current TS Implementation ? Thanks for your feedback and help @phryneas |
This causes a circular reference issue. Please see it here https://codesandbox.io/s/elated-golick-b7kv2n?file=/src/index.tsx |
Currently if I want to type my custom base query I'll do it with
BaseQueryFn
here is the current type
This is really nice because it's templated for a lot of parameters:
but not for
BaseQueryApi
which can be different for each project, let's say I implemented redux thunk with extra argument then myBaseQueryApi
will have different than the current oneThis is the current type of
BaseQueryApi
:Maybe we should have something like this for people that have their own extra
I've opened a PR, where we can check what is the best way to implement this #1684 (The current change are not relevent but it's just an idea)
if you think it's not relevent or if you think there are other way to type it, I can close this
The text was updated successfully, but these errors were encountered: