diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 3e54bb2f42..0358eba2fd 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -237,10 +237,16 @@ export type EndpointDefinitionWithQueryFn< rawErrorResponseSchema?: never } -type BaseEndpointTypes = { +type BaseEndpointTypes< + QueryArg, + BaseQuery extends BaseQueryFn, + ResultType, + RawResultType, +> = { QueryArg: QueryArg BaseQuery: BaseQuery ResultType: ResultType + RawResultType: RawResultType } interface CommonEndpointDefinition< @@ -519,7 +525,8 @@ type QueryTypes< TagTypes extends string, ResultType, ReducerPath extends string = string, -> = BaseEndpointTypes & { + RawResultType extends BaseQueryResult = BaseQueryResult, +> = BaseEndpointTypes & { /** * The endpoint definition type. To be used with some internal generic types. * @example @@ -547,6 +554,7 @@ export interface QueryExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, + RawResultType extends BaseQueryResult = BaseQueryResult, > extends CacheLifecycleQueryExtraOptions< ResultType, QueryArg, @@ -791,7 +799,14 @@ export interface QueryExtraOptions< /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! */ - Types?: QueryTypes + Types?: QueryTypes< + QueryArg, + BaseQuery, + TagTypes, + ResultType, + ReducerPath, + RawResultType + > } export type QueryDefinition< @@ -802,7 +817,14 @@ export type QueryDefinition< ReducerPath extends string = string, RawResultType extends BaseQueryResult = BaseQueryResult, > = BaseEndpointDefinition & - QueryExtraOptions + QueryExtraOptions< + TagTypes, + ResultType, + QueryArg, + BaseQuery, + ReducerPath, + RawResultType + > export type InfiniteQueryTypes< QueryArg, @@ -811,7 +833,8 @@ export type InfiniteQueryTypes< TagTypes extends string, ResultType, ReducerPath extends string = string, -> = BaseEndpointTypes & { + RawResultType extends BaseQueryResult = BaseQueryResult, +> = BaseEndpointTypes & { /** * The endpoint definition type. To be used with some internal generic types. * @example @@ -838,6 +861,7 @@ export interface InfiniteQueryExtraOptions< PageParam, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, + RawResultType extends BaseQueryResult = BaseQueryResult, > extends CacheLifecycleInfiniteQueryExtraOptions< InfiniteData, QueryArg, @@ -987,7 +1011,8 @@ export interface InfiniteQueryExtraOptions< BaseQuery, TagTypes, ResultType, - ReducerPath + ReducerPath, + RawResultType > } @@ -1013,7 +1038,8 @@ export type InfiniteQueryDefinition< QueryArg, PageParam, BaseQuery, - ReducerPath + ReducerPath, + RawResultType > type MutationTypes< @@ -1022,7 +1048,8 @@ type MutationTypes< TagTypes extends string, ResultType, ReducerPath extends string = string, -> = BaseEndpointTypes & { + RawResultType extends BaseQueryResult = BaseQueryResult, +> = BaseEndpointTypes & { /** * The endpoint definition type. To be used with some internal generic types. * @example @@ -1050,6 +1077,7 @@ export interface MutationExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, + RawResultType extends BaseQueryResult = BaseQueryResult, > extends CacheLifecycleMutationExtraOptions< ResultType, QueryArg, @@ -1124,7 +1152,14 @@ export interface MutationExtraOptions< /** * All of these are `undefined` at runtime, purely to be used in TypeScript declarations! */ - Types?: MutationTypes + Types?: MutationTypes< + QueryArg, + BaseQuery, + TagTypes, + ResultType, + ReducerPath, + RawResultType + > } export type MutationDefinition< @@ -1135,7 +1170,14 @@ export type MutationDefinition< ReducerPath extends string = string, RawResultType extends BaseQueryResult = BaseQueryResult, > = BaseEndpointDefinition & - MutationExtraOptions + MutationExtraOptions< + TagTypes, + ResultType, + QueryArg, + BaseQuery, + ReducerPath, + RawResultType + > export type EndpointDefinition< QueryArg, diff --git a/packages/toolkit/src/query/tests/createApi.test-d.ts b/packages/toolkit/src/query/tests/createApi.test-d.ts index 96bcef5946..ad86da1473 100644 --- a/packages/toolkit/src/query/tests/createApi.test-d.ts +++ b/packages/toolkit/src/query/tests/createApi.test-d.ts @@ -498,6 +498,7 @@ describe('type tests', () => { id: number }>() expectTypeOf(api.endpoints.query.Types.ResultType).toEqualTypeOf() + expectTypeOf(api.endpoints.query.Types.RawResultType).toBeAny() expectTypeOf(api.endpoints.query2.Types.QueryArg).toEqualTypeOf<{ id: number @@ -505,11 +506,15 @@ describe('type tests', () => { expectTypeOf( api.endpoints.query2.Types.ResultType, ).toEqualTypeOf() + expectTypeOf(api.endpoints.query2.Types.RawResultType).toBeAny() expectTypeOf(api.endpoints.query3.Types.QueryArg).toEqualTypeOf() expectTypeOf(api.endpoints.query3.Types.ResultType).toEqualTypeOf< EntityState >() + expectTypeOf(api.endpoints.query3.Types.RawResultType).toEqualTypeOf< + Post[] + >() }) }) })