Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export interface QueryBaseLifecycleApi<
updateCachedData(updateRecipe: Recipe<ResultType>): PatchCollection
}

export type MutationBaseLifecycleApi<
QueryArg,
BaseQuery extends BaseQueryFn,
ResultType,
ReducerPath extends string = string,
> = LifecycleApi<ReducerPath> & {
export interface MutationBaseLifecycleApi<
in QueryArg,
in BaseQuery extends BaseQueryFn,
in ResultType,
in ReducerPath extends string = string,
> extends LifecycleApi<ReducerPath> {
/**
* Gets the current value of this cache entry.
*/
Expand All @@ -70,7 +70,7 @@ export type MutationBaseLifecycleApi<
>
}

type LifecycleApi<ReducerPath extends string = string> = {
type LifecycleApi<in ReducerPath extends string = string> = {
/**
* The dispatch method for the store
*/
Expand All @@ -89,7 +89,10 @@ type LifecycleApi<ReducerPath extends string = string> = {
requestId: string
}

type CacheLifecyclePromises<ResultType = unknown, MetaType = unknown> = {
type CacheLifecyclePromises<
out ResultType = unknown,
out MetaType = unknown,
> = {
/**
* Promise that will resolve with the first value for this cache key.
* This allows you to `await` until an actual value is in cache.
Expand Down Expand Up @@ -125,10 +128,10 @@ type CacheLifecyclePromises<ResultType = unknown, MetaType = unknown> = {
}

export interface QueryCacheLifecycleApi<
QueryArg,
BaseQuery extends BaseQueryFn,
ResultType,
ReducerPath extends string = string,
in QueryArg,
in BaseQuery extends BaseQueryFn,
out ResultType,
in ReducerPath extends string = string,
> extends QueryBaseLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,
CacheLifecyclePromises<ResultType, BaseQueryMeta<BaseQuery>> {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ export type QueryLifecycleMutationExtraOptions<
}

export interface QueryLifecycleApi<
QueryArg,
BaseQuery extends BaseQueryFn,
ResultType,
ReducerPath extends string = string,
in QueryArg,
in BaseQuery extends BaseQueryFn,
out ResultType,
in ReducerPath extends string = string,
> extends QueryBaseLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,
QueryLifecyclePromises<ResultType, BaseQuery> {}

Expand Down
55 changes: 29 additions & 26 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export type SchemaFailureConverter<BaseQuery extends BaseQueryFn> = (
export type EndpointDefinitionWithQuery<
QueryArg,
BaseQuery extends BaseQueryFn,
ResultType,
RawResultType extends BaseQueryResult<BaseQuery>,
out ResultType,
out RawResultType extends BaseQueryResult<BaseQuery>,
> = {
/**
* `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking.
Expand Down Expand Up @@ -566,12 +566,13 @@ type QueryTypes<
* @public
*/
export interface QueryExtraOptions<
TagTypes extends string,
ResultType,
QueryArg,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string,
RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
out TagTypes extends string,
in out ResultType,
in out QueryArg,
out BaseQuery extends BaseQueryFn,
out ReducerPath extends string = string,
out RawResultType extends
BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
> extends CacheLifecycleQueryExtraOptions<
ResultType,
QueryArg,
Expand Down Expand Up @@ -872,13 +873,14 @@ export type InfiniteQueryTypes<
}

export interface InfiniteQueryExtraOptions<
TagTypes extends string,
ResultType,
QueryArg,
PageParam,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string,
RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
out TagTypes extends string,
in out ResultType,
in out QueryArg,
in out PageParam,
out BaseQuery extends BaseQueryFn,
out ReducerPath extends string = string,
out RawResultType extends
BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
> extends CacheLifecycleInfiniteQueryExtraOptions<
InfiniteData<ResultType, PageParam>,
QueryArg,
Expand Down Expand Up @@ -1089,12 +1091,13 @@ type MutationTypes<
* @public
*/
export interface MutationExtraOptions<
TagTypes extends string,
ResultType,
QueryArg,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string,
RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
out TagTypes extends string,
in out ResultType,
in out QueryArg,
out BaseQuery extends BaseQueryFn,
out ReducerPath extends string = string,
out RawResultType extends
BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
> extends CacheLifecycleMutationExtraOptions<
ResultType,
QueryArg,
Expand Down Expand Up @@ -1262,11 +1265,11 @@ export function isAnyQueryDefinition(
return isQueryDefinition(e) || isInfiniteQueryDefinition(e)
}

export type EndpointBuilder<
BaseQuery extends BaseQueryFn,
TagTypes extends string,
ReducerPath extends string,
> = {
export interface EndpointBuilder<
out BaseQuery extends BaseQueryFn,
out TagTypes extends string,
out ReducerPath extends string,
> {
/**
* An endpoint definition that retrieves data, and may provide tags to the cache.
*
Expand Down
7 changes: 7 additions & 0 deletions packages/toolkit/src/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'
import type { MutationBaseLifecycleApi } from './core/buildMiddleware/cacheLifecycle'

export type {
CombinedState,
Expand Down Expand Up @@ -104,3 +105,9 @@ export type {
} from './tsHelpers'

export { NamedSchemaError } from './standardSchema'

// This is for type portability when using interfaces that we don't want to expose
// interfaces are sometimes preferred over type aliases for faster type inference
export declare namespace RTKInternalDoNotUse {
export { MutationBaseLifecycleApi }
}
Loading