Skip to content

Commit

Permalink
Drop generic and make extraOptions unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Oct 14, 2024
1 parent 41487fd commit 896e4df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
25 changes: 6 additions & 19 deletions packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ function stripUndefined(obj: any) {
return copy
}

export type FetchBaseQueryArgs<ExtraOptions = {}> = {
export type FetchBaseQueryArgs = {
baseUrl?: string
prepareHeaders?: (
headers: Headers,
api: Pick<
BaseQueryApi,
'getState' | 'extra' | 'endpoint' | 'type' | 'forced'
> & { arg: string | FetchArgs; extraOptions: ExtraOptions },
> & { arg: string | FetchArgs; extraOptions: unknown },
) => MaybePromise<Headers | void>
fetchFn?: (
input: RequestInfo,
Expand Down Expand Up @@ -188,21 +188,8 @@ export type FetchBaseQueryMeta = { request: Request; response?: Response }
* @param {number} timeout
* A number in milliseconds that represents the maximum time a request can take before timing out.
*/
export function fetchBaseQuery(options?: FetchBaseQueryArgs<{}>): BaseQueryFn<
string | FetchArgs,
unknown,
FetchBaseQueryError,
{},
FetchBaseQueryMeta
>
export function fetchBaseQuery<ExtraOptions>(options?: FetchBaseQueryArgs<ExtraOptions>): BaseQueryFn<
string | FetchArgs,
unknown,
FetchBaseQueryError,
ExtraOptions,
FetchBaseQueryMeta
>
export function fetchBaseQuery<ExtraOptions>({

export function fetchBaseQuery({
baseUrl,
prepareHeaders = (x) => x,
fetchFn = defaultFetchFn,
Expand All @@ -214,11 +201,11 @@ export function fetchBaseQuery<ExtraOptions>({
responseHandler: globalResponseHandler,
validateStatus: globalValidateStatus,
...baseFetchOptions
}: FetchBaseQueryArgs<ExtraOptions> = {}): BaseQueryFn<
}: FetchBaseQueryArgs = {}): BaseQueryFn<
string | FetchArgs,
unknown,
FetchBaseQueryError,
ExtraOptions,
{},
FetchBaseQueryMeta
> {
if (typeof fetch === 'undefined' && fetchFn === defaultFetchFn) {
Expand Down
11 changes: 2 additions & 9 deletions packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,9 @@ describe('fetchBaseQuery', () => {

test('can be instantiated with a `ExtraOptions` generic and `extraOptions` will be available in `prepareHeaders', async () => {
const prepare = vitest.fn()
const baseQuery = fetchBaseQuery<{ foo?: string; bar?: number }>({
const baseQuery = fetchBaseQuery({
prepareHeaders(headers, api) {
expectTypeOf(api.extraOptions).toEqualTypeOf<{
foo?: string
bar?: number
}>()
expectTypeOf(api.extraOptions).toEqualTypeOf<unknown>()
prepare.apply(undefined, arguments as unknown as any[])
},
})
Expand All @@ -884,8 +881,6 @@ describe('fetchBaseQuery', () => {
extraOptions: {
foo: 'asd',
bar: 1,
// @ts-expect-error
baz: 5,
},
}),
testMutation: build.mutation({
Expand All @@ -897,8 +892,6 @@ describe('fetchBaseQuery', () => {
extraOptions: {
foo: 'qwe',
bar: 15,
// @ts-expect-error
baz: 5,
},
}),
}
Expand Down

0 comments on commit 896e4df

Please sign in to comment.