Skip to content
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

Type bug: RTK Query - type for extraOptions only works as an object with optional properties #1087

Open
Shrugsy opened this issue May 25, 2021 · 7 comments · May be fixed by #4208
Open

Type bug: RTK Query - type for extraOptions only works as an object with optional properties #1087

Shrugsy opened this issue May 25, 2021 · 7 comments · May be fixed by #4208
Labels
bug Something isn't working rtk-query typescript

Comments

@Shrugsy
Copy link
Collaborator

Shrugsy commented May 25, 2021

Description

When defining a baseQuery and providing a type for extraOptions, trying to use the baseQuery with createApi has a typescript error unless the extraOptions type is an object with only optional properties.

e.g. will not work:

BaseQueryFn<
  string, // Args
  unknown, // Result
  { reason: string }, // Error
  { shout: boolean }, // DefinitionExtraOptions
  { timestamp: number } // Meta
>

will work:

BaseQueryFn<
  string, // Args
  unknown, // Result
  { reason: string }, // Error
  { shout?: boolean }, // DefinitionExtraOptions
  { timestamp: number } // Meta
>

Version

1.6.0-beta.0

Reproduction example

https://codesandbox.io/s/basequery-extraoptions-type-bug-w4kxt?file=/src/index.ts

Type 'BaseQueryFn<string, unknown, { reason: string; }, { shout: boolean; }, { timestamp: number; }>' is not assignable to type 'BaseQueryFn<any, unknown, unknown, {}, {}>'.
  Property 'shout' is missing in type '{}' but required in type '{ shout: boolean; }'.ts(2322)
index.ts(7, 5): 'shout' is declared here.
createApi.d.ts(24, 5): The expected type comes from property 'baseQuery' which is declared here on type 'CreateApiOptions<BaseQueryFn<any, unknown, unknown, {}, {}>, Record<string, EndpointDefinition<any, any, any, any, string>>, "api", never>'
@phryneas
Copy link
Member

phryneas commented Jun 5, 2021

I think we can postpone that one for a 1.7, right?

@phryneas phryneas added this to the 1.7 milestone Jun 5, 2021
@phryneas phryneas added the bug Something isn't working label Jun 5, 2021
@Shrugsy
Copy link
Collaborator Author

Shrugsy commented Jun 6, 2021

Yep definitely

@markerikson
Copy link
Collaborator

This still happening?

@Shrugsy
Copy link
Collaborator Author

Shrugsy commented Nov 5, 2021

Yeah, still happening on 1.7.0-beta.0

I haven't looked into it so I don't know how much trouble the fix would be, but I would say that it's a rare enough problem that it could be pushed back for a later version

@markerikson markerikson modified the milestones: 1.7, 1.8 Nov 5, 2021
@dastardlychimp
Copy link

I ran into this today. If this isn't going to be fixed anytime soon, it would be nice if the docs were updated to indicate only optional properties were allowed.

@phryneas
Copy link
Member

phryneas commented Mar 9, 2022

@dastardlychimp PRs are always welcome.
We only have so much time and this is just not very high priority.

@markerikson
Copy link
Collaborator

This has been pushed through the 1.7 and 1.8 milestones. Coming up on 1.9, and this still is just not a high enough priority. Dropping out of the 1.9 milestone.

@markerikson markerikson removed this from the 1.9 milestone Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rtk-query typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants