Skip to content

Commit 896e4df

Browse files
committed
Drop generic and make extraOptions unknown
1 parent 41487fd commit 896e4df

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

packages/toolkit/src/query/fetchBaseQuery.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ function stripUndefined(obj: any) {
105105
return copy
106106
}
107107

108-
export type FetchBaseQueryArgs<ExtraOptions = {}> = {
108+
export type FetchBaseQueryArgs = {
109109
baseUrl?: string
110110
prepareHeaders?: (
111111
headers: Headers,
112112
api: Pick<
113113
BaseQueryApi,
114114
'getState' | 'extra' | 'endpoint' | 'type' | 'forced'
115-
> & { arg: string | FetchArgs; extraOptions: ExtraOptions },
115+
> & { arg: string | FetchArgs; extraOptions: unknown },
116116
) => MaybePromise<Headers | void>
117117
fetchFn?: (
118118
input: RequestInfo,
@@ -188,21 +188,8 @@ export type FetchBaseQueryMeta = { request: Request; response?: Response }
188188
* @param {number} timeout
189189
* A number in milliseconds that represents the maximum time a request can take before timing out.
190190
*/
191-
export function fetchBaseQuery(options?: FetchBaseQueryArgs<{}>): BaseQueryFn<
192-
string | FetchArgs,
193-
unknown,
194-
FetchBaseQueryError,
195-
{},
196-
FetchBaseQueryMeta
197-
>
198-
export function fetchBaseQuery<ExtraOptions>(options?: FetchBaseQueryArgs<ExtraOptions>): BaseQueryFn<
199-
string | FetchArgs,
200-
unknown,
201-
FetchBaseQueryError,
202-
ExtraOptions,
203-
FetchBaseQueryMeta
204-
>
205-
export function fetchBaseQuery<ExtraOptions>({
191+
192+
export function fetchBaseQuery({
206193
baseUrl,
207194
prepareHeaders = (x) => x,
208195
fetchFn = defaultFetchFn,
@@ -214,11 +201,11 @@ export function fetchBaseQuery<ExtraOptions>({
214201
responseHandler: globalResponseHandler,
215202
validateStatus: globalValidateStatus,
216203
...baseFetchOptions
217-
}: FetchBaseQueryArgs<ExtraOptions> = {}): BaseQueryFn<
204+
}: FetchBaseQueryArgs = {}): BaseQueryFn<
218205
string | FetchArgs,
219206
unknown,
220207
FetchBaseQueryError,
221-
ExtraOptions,
208+
{},
222209
FetchBaseQueryMeta
223210
> {
224211
if (typeof fetch === 'undefined' && fetchFn === defaultFetchFn) {

packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,9 @@ describe('fetchBaseQuery', () => {
856856

857857
test('can be instantiated with a `ExtraOptions` generic and `extraOptions` will be available in `prepareHeaders', async () => {
858858
const prepare = vitest.fn()
859-
const baseQuery = fetchBaseQuery<{ foo?: string; bar?: number }>({
859+
const baseQuery = fetchBaseQuery({
860860
prepareHeaders(headers, api) {
861-
expectTypeOf(api.extraOptions).toEqualTypeOf<{
862-
foo?: string
863-
bar?: number
864-
}>()
861+
expectTypeOf(api.extraOptions).toEqualTypeOf<unknown>()
865862
prepare.apply(undefined, arguments as unknown as any[])
866863
},
867864
})
@@ -884,8 +881,6 @@ describe('fetchBaseQuery', () => {
884881
extraOptions: {
885882
foo: 'asd',
886883
bar: 1,
887-
// @ts-expect-error
888-
baz: 5,
889884
},
890885
}),
891886
testMutation: build.mutation({
@@ -897,8 +892,6 @@ describe('fetchBaseQuery', () => {
897892
extraOptions: {
898893
foo: 'qwe',
899894
bar: 15,
900-
// @ts-expect-error
901-
baz: 5,
902895
},
903896
}),
904897
}

0 commit comments

Comments
 (0)