Skip to content

Commit 389d5bc

Browse files
committed
try something
1 parent 0352f34 commit 389d5bc

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

packages/toolkit/src/query/createApi.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface CreateApiOptions<
1717
BaseQuery extends BaseQueryFn,
1818
Definitions extends EndpointDefinitions,
1919
ReducerPath extends string = 'api',
20-
TagTypes extends string = never
20+
TagTypes extends string = never,
2121
> {
2222
/**
2323
* The base query used by each endpoint if no `queryFn` option is specified. RTK Query exports a utility called [fetchBaseQuery](./fetchBaseQuery) as a lightweight wrapper around `fetch` for common use-cases. See [Customizing Queries](../../rtk-query/usage/customizing-queries) if `fetchBaseQuery` does not handle your requirements.
@@ -97,7 +97,7 @@ export interface CreateApiOptions<
9797
* Endpoints are just a set of operations that you want to perform against your server. You define them as an object using the builder syntax. There are two basic endpoint types: [`query`](../../rtk-query/usage/queries) and [`mutation`](../../rtk-query/usage/mutations).
9898
*/
9999
endpoints(
100-
build: EndpointBuilder<BaseQuery, TagTypes, ReducerPath>
100+
build: EndpointBuilder<BaseQuery, TagTypes, ReducerPath>,
101101
): Definitions
102102
/**
103103
* Defaults to `60` _(this value is in seconds)_. This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache.
@@ -200,7 +200,7 @@ export interface CreateApiOptions<
200200
reducerPath,
201201
}: {
202202
reducerPath: ReducerPath
203-
}
203+
},
204204
) =>
205205
| undefined
206206
| CombinedState<
@@ -220,9 +220,9 @@ export type CreateApi<Modules extends ModuleName> = {
220220
BaseQuery extends BaseQueryFn,
221221
Definitions extends EndpointDefinitions,
222222
ReducerPath extends string = 'api',
223-
TagTypes extends string = never
223+
TagTypes extends string = never,
224224
>(
225-
options: CreateApiOptions<BaseQuery, Definitions, ReducerPath, TagTypes>
225+
options: CreateApiOptions<BaseQuery, Definitions, ReducerPath, TagTypes>,
226226
): Api<BaseQuery, Definitions, ReducerPath, TagTypes, Modules>
227227
}
228228

@@ -249,14 +249,14 @@ export type CreateApi<Modules extends ModuleName> = {
249249
* @param modules - A variable number of modules that customize how the `createApi` method handles endpoints
250250
* @returns A `createApi` method using the provided `modules`.
251251
*/
252-
export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
253-
...modules: Modules
254-
): CreateApi<Modules[number]['name']> {
252+
export function buildCreateApi<Modules extends [any, ...any[]]>(
253+
...modules: [...{ [K in keyof Modules]: Module<Modules[K]> }]
254+
): CreateApi<Modules[number]> {
255255
return function baseCreateApi(options) {
256256
const extractRehydrationInfo = weakMapMemoize((action: UnknownAction) =>
257257
options.extractRehydrationInfo?.(action, {
258258
reducerPath: (options.reducerPath ?? 'api') as any,
259-
})
259+
}),
260260
)
261261

262262
const optionsWithDefaults: CreateApiOptions<any, any, any, any> = {
@@ -305,7 +305,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
305305
apiUid: nanoid(),
306306
extractRehydrationInfo,
307307
hasRehydrationInfo: weakMapMemoize(
308-
(action) => extractRehydrationInfo(action) != null
308+
(action) => extractRehydrationInfo(action) != null,
309309
),
310310
}
311311

@@ -321,14 +321,14 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
321321
}
322322
if (endpoints) {
323323
for (const [endpointName, partialDefinition] of Object.entries(
324-
endpoints
324+
endpoints,
325325
)) {
326326
if (typeof partialDefinition === 'function') {
327327
partialDefinition(context.endpointDefinitions[endpointName])
328328
} else {
329329
Object.assign(
330330
context.endpointDefinitions[endpointName] || {},
331-
partialDefinition
331+
partialDefinition,
332332
)
333333
}
334334
}
@@ -338,19 +338,19 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
338338
} as Api<BaseQueryFn, {}, string, string, Modules[number]['name']>
339339

340340
const initializedModules = modules.map((m) =>
341-
m.init(api as any, optionsWithDefaults as any, context)
341+
m.init(api as any, optionsWithDefaults as any, context),
342342
)
343343

344344
function injectEndpoints(
345-
inject: Parameters<typeof api.injectEndpoints>[0]
345+
inject: Parameters<typeof api.injectEndpoints>[0],
346346
) {
347347
const evaluatedEndpoints = inject.endpoints({
348-
query: (x) => ({ ...x, type: DefinitionType.query } as any),
349-
mutation: (x) => ({ ...x, type: DefinitionType.mutation } as any),
348+
query: (x) => ({ ...x, type: DefinitionType.query }) as any,
349+
mutation: (x) => ({ ...x, type: DefinitionType.mutation }) as any,
350350
})
351351

352352
for (const [endpointName, definition] of Object.entries(
353-
evaluatedEndpoints
353+
evaluatedEndpoints,
354354
)) {
355355
if (
356356
!inject.overrideExisting &&
@@ -361,7 +361,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
361361
process.env.NODE_ENV === 'development'
362362
) {
363363
console.error(
364-
`called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``
364+
`called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``,
365365
)
366366
}
367367

0 commit comments

Comments
 (0)