@@ -46,6 +46,7 @@ type EndpointDefinitionWithQuery<
46
46
QueryArg ,
47
47
BaseQuery extends BaseQueryFn ,
48
48
ResultType ,
49
+ RawResultType extends BaseQueryResult < BaseQuery > ,
49
50
> = {
50
51
/**
51
52
* `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.
@@ -91,7 +92,7 @@ type EndpointDefinitionWithQuery<
91
92
* A function to manipulate the data returned by a query or mutation.
92
93
*/
93
94
transformResponse ?(
94
- baseQueryReturnValue : BaseQueryResult < BaseQuery > ,
95
+ baseQueryReturnValue : RawResultType ,
95
96
meta : BaseQueryMeta < BaseQuery > ,
96
97
arg : QueryArg ,
97
98
) : ResultType | Promise < ResultType >
@@ -105,7 +106,7 @@ type EndpointDefinitionWithQuery<
105
106
) : unknown
106
107
107
108
/** A schema for the result *before* it's passed to `transformResponse` */
108
- rawResponseSchema ?: StandardSchemaV1 < BaseQueryResult < BaseQuery > >
109
+ rawResponseSchema ?: StandardSchemaV1 < RawResultType >
109
110
110
111
/** A schema for the error object returned by the `query` or `queryFn`, *before* it's passed to `transformErrorResponse` */
111
112
rawErrorResponseSchema ?: StandardSchemaV1 < BaseQueryError < BaseQuery > >
@@ -183,10 +184,16 @@ export type BaseEndpointDefinition<
183
184
QueryArg ,
184
185
BaseQuery extends BaseQueryFn ,
185
186
ResultType ,
187
+ RawResultType extends BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
186
188
> = (
187
189
| ( [ CastAny < BaseQueryResult < BaseQuery > , { } > ] extends [ NEVER ]
188
190
? never
189
- : EndpointDefinitionWithQuery < QueryArg , BaseQuery , ResultType > )
191
+ : EndpointDefinitionWithQuery <
192
+ QueryArg ,
193
+ BaseQuery ,
194
+ ResultType ,
195
+ RawResultType
196
+ > )
190
197
| EndpointDefinitionWithQueryFn < QueryArg , BaseQuery , ResultType >
191
198
) & {
192
199
/** A schema for the arguments to be passed to the `query` or `queryFn` */
@@ -550,7 +557,8 @@ export type QueryDefinition<
550
557
TagTypes extends string ,
551
558
ResultType ,
552
559
ReducerPath extends string = string ,
553
- > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType > &
560
+ RawResultType extends BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
561
+ > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType , RawResultType > &
554
562
QueryExtraOptions < TagTypes , ResultType , QueryArg , BaseQuery , ReducerPath >
555
563
556
564
export type InfiniteQueryTypes <
@@ -743,12 +751,14 @@ export type InfiniteQueryDefinition<
743
751
TagTypes extends string ,
744
752
ResultType ,
745
753
ReducerPath extends string = string ,
754
+ RawResultType extends BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
746
755
> =
747
756
// Infinite query endpoints receive `{queryArg, pageParam}`
748
757
BaseEndpointDefinition <
749
758
InfiniteQueryCombinedArg < QueryArg , PageParam > ,
750
759
BaseQuery ,
751
- ResultType
760
+ ResultType ,
761
+ RawResultType
752
762
> &
753
763
InfiniteQueryExtraOptions <
754
764
TagTypes ,
@@ -876,7 +886,8 @@ export type MutationDefinition<
876
886
TagTypes extends string ,
877
887
ResultType ,
878
888
ReducerPath extends string = string ,
879
- > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType > &
889
+ RawResultType extends BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
890
+ > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType , RawResultType > &
880
891
MutationExtraOptions < TagTypes , ResultType , QueryArg , BaseQuery , ReducerPath >
881
892
882
893
export type EndpointDefinition <
@@ -960,9 +971,21 @@ export type EndpointBuilder<
960
971
*});
961
972
*```
962
973
*/
963
- query < ResultType , QueryArg > (
974
+ query <
975
+ ResultType ,
976
+ QueryArg ,
977
+ RawResultType extends
978
+ BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
979
+ > (
964
980
definition : OmitFromUnion <
965
- QueryDefinition < QueryArg , BaseQuery , TagTypes , ResultType , ReducerPath > ,
981
+ QueryDefinition <
982
+ QueryArg ,
983
+ BaseQuery ,
984
+ TagTypes ,
985
+ ResultType ,
986
+ ReducerPath ,
987
+ RawResultType
988
+ > ,
966
989
'type'
967
990
> ,
968
991
) : QueryDefinition < QueryArg , BaseQuery , TagTypes , ResultType , ReducerPath >
@@ -992,14 +1015,20 @@ export type EndpointBuilder<
992
1015
* });
993
1016
* ```
994
1017
*/
995
- mutation < ResultType , QueryArg > (
1018
+ mutation <
1019
+ ResultType ,
1020
+ QueryArg ,
1021
+ RawResultType extends
1022
+ BaseQueryResult < BaseQuery > = BaseQueryResult < BaseQuery > ,
1023
+ > (
996
1024
definition : OmitFromUnion <
997
1025
MutationDefinition <
998
1026
QueryArg ,
999
1027
BaseQuery ,
1000
1028
TagTypes ,
1001
1029
ResultType ,
1002
- ReducerPath
1030
+ ReducerPath ,
1031
+ RawResultType
1003
1032
> ,
1004
1033
'type'
1005
1034
> ,
@@ -1066,27 +1095,31 @@ export function expandTagDescription(
1066
1095
return typeof description === 'string' ? { type : description } : description
1067
1096
}
1068
1097
1069
- export type QueryArgFrom < D extends BaseEndpointDefinition < any , any , any > > =
1070
- D extends BaseEndpointDefinition < infer QA , any , any > ? QA : never
1098
+ export type QueryArgFrom < D extends BaseEndpointDefinition < any , any , any , any > > =
1099
+ D extends BaseEndpointDefinition < infer QA , any , any , any > ? QA : never
1071
1100
1072
1101
// Just extracting `QueryArg` from `BaseEndpointDefinition`
1073
1102
// doesn't sufficiently match here.
1074
1103
// We need to explicitly match against `InfiniteQueryDefinition`
1075
1104
export type InfiniteQueryArgFrom <
1076
- D extends BaseEndpointDefinition < any , any , any > ,
1077
- > = D extends InfiniteQueryDefinition < infer QA , any , any , any , any > ? QA : never
1105
+ D extends BaseEndpointDefinition < any , any , any , any > ,
1106
+ > =
1107
+ D extends InfiniteQueryDefinition < infer QA , any , any , any , any , any >
1108
+ ? QA
1109
+ : never
1078
1110
1079
1111
export type QueryArgFromAnyQuery <
1080
- D extends BaseEndpointDefinition < any , any , any > ,
1112
+ D extends BaseEndpointDefinition < any , any , any , any > ,
1081
1113
> =
1082
- D extends InfiniteQueryDefinition < any , any , any , any , any >
1114
+ D extends InfiniteQueryDefinition < any , any , any , any , any , any >
1083
1115
? InfiniteQueryArgFrom < D >
1084
1116
: D extends QueryDefinition < any , any , any , any >
1085
1117
? QueryArgFrom < D >
1086
1118
: never
1087
1119
1088
- export type ResultTypeFrom < D extends BaseEndpointDefinition < any , any , any > > =
1089
- D extends BaseEndpointDefinition < any , any , infer RT > ? RT : unknown
1120
+ export type ResultTypeFrom <
1121
+ D extends BaseEndpointDefinition < any , any , any , any > ,
1122
+ > = D extends BaseEndpointDefinition < any , any , infer RT , any > ? RT : unknown
1090
1123
1091
1124
export type ReducerPathFrom <
1092
1125
D extends EndpointDefinition < any , any , any , any , any > ,
@@ -1096,9 +1129,11 @@ export type TagTypesFrom<D extends EndpointDefinition<any, any, any, any>> =
1096
1129
D extends EndpointDefinition < any , any , infer RP , any > ? RP : unknown
1097
1130
1098
1131
export type PageParamFrom <
1099
- D extends InfiniteQueryDefinition < any , any , any , any , any > ,
1132
+ D extends InfiniteQueryDefinition < any , any , any , any , any , any > ,
1100
1133
> =
1101
- D extends InfiniteQueryDefinition < any , infer PP , any , any , any > ? PP : unknown
1134
+ D extends InfiniteQueryDefinition < any , infer PP , any , any , any , any >
1135
+ ? PP
1136
+ : unknown
1102
1137
1103
1138
export type InfiniteQueryCombinedArg < QueryArg , PageParam > = {
1104
1139
queryArg : QueryArg
0 commit comments