Skip to content

Commit ed567b7

Browse files
committed
persist raw result type after building
1 parent 23c00ee commit ed567b7

File tree

1 file changed

+70
-24
lines changed

1 file changed

+70
-24
lines changed

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -913,38 +913,54 @@ export type EndpointDefinition<
913913
ResultType,
914914
ReducerPath extends string = string,
915915
PageParam = any,
916+
RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
916917
> =
917-
| QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
918-
| MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
918+
| QueryDefinition<
919+
QueryArg,
920+
BaseQuery,
921+
TagTypes,
922+
ResultType,
923+
ReducerPath,
924+
RawResultType
925+
>
926+
| MutationDefinition<
927+
QueryArg,
928+
BaseQuery,
929+
TagTypes,
930+
ResultType,
931+
ReducerPath,
932+
RawResultType
933+
>
919934
| InfiniteQueryDefinition<
920935
QueryArg,
921936
PageParam,
922937
BaseQuery,
923938
TagTypes,
924939
ResultType,
925-
ReducerPath
940+
ReducerPath,
941+
RawResultType
926942
>
927943

928944
export type EndpointDefinitions = Record<
929945
string,
930-
EndpointDefinition<any, any, any, any>
946+
EndpointDefinition<any, any, any, any, any, any, any>
931947
>
932948

933949
export function isQueryDefinition(
934-
e: EndpointDefinition<any, any, any, any>,
935-
): e is QueryDefinition<any, any, any, any> {
950+
e: EndpointDefinition<any, any, any, any, any, any, any>,
951+
): e is QueryDefinition<any, any, any, any, any, any> {
936952
return e.type === DefinitionType.query
937953
}
938954

939955
export function isMutationDefinition(
940-
e: EndpointDefinition<any, any, any, any>,
941-
): e is MutationDefinition<any, any, any, any> {
956+
e: EndpointDefinition<any, any, any, any, any, any, any>,
957+
): e is MutationDefinition<any, any, any, any, any, any> {
942958
return e.type === DefinitionType.mutation
943959
}
944960

945961
export function isInfiniteQueryDefinition(
946-
e: EndpointDefinition<any, any, any, any>,
947-
): e is InfiniteQueryDefinition<any, any, any, any, any> {
962+
e: EndpointDefinition<any, any, any, any, any, any, any>,
963+
): e is InfiniteQueryDefinition<any, any, any, any, any, any, any> {
948964
return e.type === DefinitionType.infinitequery
949965
}
950966

@@ -996,7 +1012,15 @@ export type EndpointBuilder<
9961012
>,
9971013
'type'
9981014
>,
999-
): QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
1015+
): QueryDefinition<
1016+
QueryArg,
1017+
BaseQuery,
1018+
TagTypes,
1019+
ResultType,
1020+
ReducerPath,
1021+
RawResultType
1022+
>
1023+
10001024
/**
10011025
* An endpoint definition that alters data on the server or will possibly invalidate the cache.
10021026
*
@@ -1040,17 +1064,31 @@ export type EndpointBuilder<
10401064
>,
10411065
'type'
10421066
>,
1043-
): MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>
1067+
): MutationDefinition<
1068+
QueryArg,
1069+
BaseQuery,
1070+
TagTypes,
1071+
ResultType,
1072+
ReducerPath,
1073+
RawResultType
1074+
>
10441075

1045-
infiniteQuery<ResultType, QueryArg, PageParam>(
1076+
infiniteQuery<
1077+
ResultType,
1078+
QueryArg,
1079+
PageParam,
1080+
RawResultType extends
1081+
BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1082+
>(
10461083
definition: OmitFromUnion<
10471084
InfiniteQueryDefinition<
10481085
QueryArg,
10491086
PageParam,
10501087
BaseQuery,
10511088
TagTypes,
10521089
ResultType,
1053-
ReducerPath
1090+
ReducerPath,
1091+
RawResultType
10541092
>,
10551093
'type'
10561094
>,
@@ -1060,7 +1098,8 @@ export type EndpointBuilder<
10601098
BaseQuery,
10611099
TagTypes,
10621100
ResultType,
1063-
ReducerPath
1101+
ReducerPath,
1102+
RawResultType
10641103
>
10651104
}
10661105

@@ -1112,16 +1151,16 @@ export type QueryArgFrom<D extends BaseEndpointDefinition<any, any, any, any>> =
11121151
export type InfiniteQueryArgFrom<
11131152
D extends BaseEndpointDefinition<any, any, any, any>,
11141153
> =
1115-
D extends InfiniteQueryDefinition<infer QA, any, any, any, any, any>
1154+
D extends InfiniteQueryDefinition<infer QA, any, any, any, any, any, any>
11161155
? QA
11171156
: never
11181157

11191158
export type QueryArgFromAnyQuery<
11201159
D extends BaseEndpointDefinition<any, any, any, any>,
11211160
> =
1122-
D extends InfiniteQueryDefinition<any, any, any, any, any, any>
1161+
D extends InfiniteQueryDefinition<any, any, any, any, any, any, any>
11231162
? InfiniteQueryArgFrom<D>
1124-
: D extends QueryDefinition<any, any, any, any>
1163+
: D extends QueryDefinition<any, any, any, any, any, any>
11251164
? QueryArgFrom<D>
11261165
: never
11271166

@@ -1130,16 +1169,23 @@ export type ResultTypeFrom<
11301169
> = D extends BaseEndpointDefinition<any, any, infer RT, any> ? RT : unknown
11311170

11321171
export type ReducerPathFrom<
1133-
D extends EndpointDefinition<any, any, any, any, any>,
1134-
> = D extends EndpointDefinition<any, any, any, any, infer RP> ? RP : unknown
1172+
D extends EndpointDefinition<any, any, any, any, any, any, any>,
1173+
> =
1174+
D extends EndpointDefinition<any, any, any, any, infer RP, any, any>
1175+
? RP
1176+
: unknown
11351177

1136-
export type TagTypesFrom<D extends EndpointDefinition<any, any, any, any>> =
1137-
D extends EndpointDefinition<any, any, infer RP, any> ? RP : unknown
1178+
export type TagTypesFrom<
1179+
D extends EndpointDefinition<any, any, any, any, any, any, any>,
1180+
> =
1181+
D extends EndpointDefinition<any, any, infer TT, any, any, any, any>
1182+
? TT
1183+
: unknown
11381184

11391185
export type PageParamFrom<
1140-
D extends InfiniteQueryDefinition<any, any, any, any, any, any>,
1186+
D extends InfiniteQueryDefinition<any, any, any, any, any, any, any>,
11411187
> =
1142-
D extends InfiniteQueryDefinition<any, infer PP, any, any, any, any>
1188+
D extends InfiniteQueryDefinition<any, infer PP, any, any, any, any, any>
11431189
? PP
11441190
: unknown
11451191

0 commit comments

Comments
 (0)