UNPKG

@reduxjs/toolkit

Version:

The official, opinionated, batteries-included toolset for efficient Redux development

38 lines (37 loc) 2.65 kB
import type { EndpointDefinitions, EndpointBuilder, EndpointDefinition, ReplaceTagTypes } from './endpointDefinitions'; import type { UnionToIntersection, NoInfer } from './tsHelpers'; import type { CoreModule } from './core/module'; import type { CreateApiOptions } from './createApi'; import type { BaseQueryFn } from './baseQueryTypes'; export interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> { } export declare type ModuleName = keyof ApiModules<any, any, any, any>; export declare type Module<Name extends ModuleName> = { name: Name; init<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string>(api: Api<BaseQuery, EndpointDefinitions, ReducerPath, TagTypes, ModuleName>, options: Required<CreateApiOptions<BaseQuery, Definitions, ReducerPath, TagTypes>>, context: ApiContext<Definitions>): { injectEndpoint(endpointName: string, definition: EndpointDefinition<any, any, any, any>): void; }; }; export interface ApiContext<Definitions extends EndpointDefinitions> { apiUid: string; endpointDefinitions: Definitions; batch(cb: () => void): void; } export declare type Api<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string, Enhancers extends ModuleName = CoreModule> = UnionToIntersection<ApiModules<BaseQuery, Definitions, ReducerPath, TagTypes>[Enhancers]> & { /** * A function to inject the endpoints into the original API, but also give you that same API with correct types for these endpoints back. Useful with code-splitting. */ injectEndpoints<NewDefinitions extends EndpointDefinitions>(_: { endpoints: (build: EndpointBuilder<BaseQuery, TagTypes, ReducerPath>) => NewDefinitions; overrideExisting?: boolean; }): Api<BaseQuery, Definitions & NewDefinitions, ReducerPath, TagTypes, Enhancers>; /** *A function to enhance a generated API with additional information. Useful with code-generation. */ enhanceEndpoints<NewTagTypes extends string = never>(_: { addTagTypes?: readonly NewTagTypes[]; endpoints?: ReplaceTagTypes<Definitions, TagTypes | NoInfer<NewTagTypes>> extends infer NewDefinitions ? { [K in keyof NewDefinitions]?: Partial<NewDefinitions[K]> | ((definition: NewDefinitions[K]) => void); } : never; }): Api<BaseQuery, ReplaceTagTypes<Definitions, TagTypes | NewTagTypes>, ReducerPath, TagTypes | NewTagTypes, Enhancers>; };