repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
531fbae
parent
f43c20f
author
Eric Bower
date
2024-01-11 19:09:49 +0000 UTC
refactor(query): better extract types from endpoints

- fix(query): pick correct `ApiError` type inside `createApi`
- `useCache` will automatically pull success type from endpoint.
6 files changed,  +1316, -287
M api-type-template.ts
+34, -27
  1@@ -21,14 +21,15 @@ ${method}<P>(
  2 ): CreateActionWithPayload<Omit<Ctx, 'payload'> & Payload<P>, P>;
  3 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
  4   req: { supervisor?: Supervisor }
  5-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
  6+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
  7 ${method}<P, ApiSuccess, ApiError = unknown>(req: {
  8   supervisor?: Supervisor;
  9 }): CreateActionWithPayload<
 10   Omit<Ctx, 'payload' | 'json'> &
 11     Payload<P> &
 12-    FetchJson<ApiSuccess, ApiError>,
 13-  P
 14+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
 15+  P,
 16+  ApiSuccess
 17 >;
 18 
 19 /**
 20@@ -45,15 +46,16 @@ ${method}<P, Gtx extends Ctx = Ctx>(
 21   fn: MiddlewareApiCo<Gtx>,
 22 ): CreateActionWithPayload<Gtx, P>;
 23 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
 24-  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>,
 25-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
 26+  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>>,
 27+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
 28 ${method}<P, ApiSuccess, ApiError = unknown>(
 29   fn: MiddlewareApiCo<Ctx>,
 30 ): CreateActionWithPayload<
 31   Omit<Ctx, 'payload' | 'json'> &
 32     Payload<P> &
 33-    FetchJson<ApiSuccess, ApiError>,
 34-  P
 35+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
 36+  P,
 37+  ApiSuccess
 38 >;
 39 
 40 /**
 41@@ -74,16 +76,17 @@ ${method}<P, Gtx extends Ctx = Ctx>(
 42 ): CreateActionWithPayload<Gtx, P>;
 43 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
 44   req: { supervisor?: Supervisor },
 45-  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>,
 46-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
 47+  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>>,
 48+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
 49 ${method}<P, ApiSuccess, ApiError = unknown>(
 50   req: { supervisor?: Supervisor },
 51   fn: MiddlewareApiCo<Ctx>,
 52 ): CreateActionWithPayload<
 53   Omit<Ctx, 'payload' | 'json'> &
 54     Payload<P> &
 55-    FetchJson<ApiSuccess, ApiError>,
 56-  P
 57+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
 58+  P,
 59+  ApiSuccess
 60 >;`;
 61   const uriMethods = methods.map((m) => uriTmpl(m)).join("\n\n");
 62 
 63@@ -97,14 +100,15 @@ ${method}<P>(
 64 ): CreateActionWithPayload<Omit<Ctx, 'payload'> & Payload<P>, P>;
 65 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
 66   name: ApiName,
 67-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
 68+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
 69 ${method}<P, ApiSuccess, ApiError = unknown>(
 70   name: ApiName,
 71 ): CreateActionWithPayload<
 72   Omit<Ctx, 'payload' | 'json'> &
 73     Payload<P> &
 74-    FetchJson<ApiSuccess, ApiError>,
 75-  P
 76+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
 77+  P,
 78+  ApiSuccess
 79 >;
 80 
 81 /**
 82@@ -122,15 +126,16 @@ ${method}<P, Gtx extends Ctx = Ctx>(
 83 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
 84   name: ApiName,
 85   req: { supervisor?: Supervisor }
 86-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
 87+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
 88 ${method}<P, ApiSuccess, ApiError = unknown>(
 89   name: ApiName,
 90   req: { supervisor?: Supervisor },
 91 ): CreateActionWithPayload<
 92   Omit<Ctx, 'payload' | 'json'> &
 93     Payload<P> &
 94-    FetchJson<ApiSuccess, ApiError>,
 95-  P
 96+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
 97+  P,
 98+  ApiSuccess
 99 >;
100 
101 /**
102@@ -151,20 +156,21 @@ ${method}<P, Gtx extends Ctx = Ctx>(
103 ): CreateActionWithPayload<Gtx, P>;
104 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
105   name: ApiName,
106-  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>,
107-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
108+  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>>,
109+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
110 ${method}<P, ApiSuccess, ApiError = unknown>(
111   name: ApiName,
112   fn: MiddlewareApiCo<
113     Omit<Ctx, 'payload' | 'json'> &
114       Payload<P> &
115-      FetchJson<ApiSuccess, ApiError>
116+      FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
117   >,
118 ): CreateActionWithPayload<
119   Omit<Ctx, 'payload' | 'json'> &
120     Payload<P> &
121-    FetchJson<ApiSuccess, ApiError>,
122-  P
123+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
124+  P,
125+  ApiSuccess
126 >;
127 
128 /**
129@@ -193,21 +199,22 @@ ${method}<P, Gtx extends Ctx = Ctx>(
130 ${method}<P extends never, ApiSuccess, ApiError = unknown>(
131   name: ApiName,
132   req: { supervisor?: Supervisor },
133-  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>,
134-): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError>>;
135+  fn: MiddlewareApiCo<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>>,
136+): CreateAction<Omit<Ctx, 'json'> & FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>, ApiSuccess>;
137 ${method}<P, ApiSuccess, ApiError = unknown>(
138   name: ApiName,
139   req: { supervisor?: Supervisor },
140   fn: MiddlewareApiCo<
141     Omit<Ctx, 'payload' | 'json'> &
142       Payload<P> &
143-      FetchJson<ApiSuccess, ApiError>
144+      FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>
145   >,
146 ): CreateActionWithPayload<
147   Omit<Ctx, 'payload' | 'json'> &
148     Payload<P> &
149-    FetchJson<ApiSuccess, ApiError>,
150-  P
151+    FetchJson<ApiSuccess, ApiError extends unknown ? Ctx["_error"] : ApiError>,
152+  P,
153+  ApiSuccess
154 >;`;
155   const regMethods = methods.map((m) => methodTmpl(m)).join("\n\n");
156 
M query/api-types.ts
+1206, -243
   1@@ -33,14 +33,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
   2     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
   3     get<P extends never, ApiSuccess, ApiError = unknown>(
   4       req: { supervisor?: Supervisor },
   5-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
   6+    ): CreateAction<
   7+      & Omit<Ctx, "json">
   8+      & FetchJson<
   9+        ApiSuccess,
  10+        ApiError extends unknown ? Ctx["_error"] : ApiError
  11+      >,
  12+      ApiSuccess
  13+    >;
  14     get<P, ApiSuccess, ApiError = unknown>(req: {
  15       supervisor?: Supervisor;
  16     }): CreateActionWithPayload<
  17       & Omit<Ctx, "payload" | "json">
  18       & Payload<P>
  19-      & FetchJson<ApiSuccess, ApiError>,
  20-      P
  21+      & FetchJson<
  22+        ApiSuccess,
  23+        ApiError extends unknown ? Ctx["_error"] : ApiError
  24+      >,
  25+      P,
  26+      ApiSuccess
  27     >;
  28 
  29     /**
  30@@ -57,15 +68,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
  31       fn: MiddlewareApiCo<Gtx>,
  32     ): CreateActionWithPayload<Gtx, P>;
  33     get<P extends never, ApiSuccess, ApiError = unknown>(
  34-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
  35-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
  36+      fn: MiddlewareApiCo<
  37+        & Omit<Ctx, "json">
  38+        & FetchJson<
  39+          ApiSuccess,
  40+          ApiError extends unknown ? Ctx["_error"] : ApiError
  41+        >
  42+      >,
  43+    ): CreateAction<
  44+      & Omit<Ctx, "json">
  45+      & FetchJson<
  46+        ApiSuccess,
  47+        ApiError extends unknown ? Ctx["_error"] : ApiError
  48+      >,
  49+      ApiSuccess
  50+    >;
  51     get<P, ApiSuccess, ApiError = unknown>(
  52       fn: MiddlewareApiCo<Ctx>,
  53     ): CreateActionWithPayload<
  54       & Omit<Ctx, "payload" | "json">
  55       & Payload<P>
  56-      & FetchJson<ApiSuccess, ApiError>,
  57-      P
  58+      & FetchJson<
  59+        ApiSuccess,
  60+        ApiError extends unknown ? Ctx["_error"] : ApiError
  61+      >,
  62+      P,
  63+      ApiSuccess
  64     >;
  65 
  66     /**
  67@@ -89,16 +117,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
  68     ): CreateActionWithPayload<Gtx, P>;
  69     get<P extends never, ApiSuccess, ApiError = unknown>(
  70       req: { supervisor?: Supervisor },
  71-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
  72-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
  73+      fn: MiddlewareApiCo<
  74+        & Omit<Ctx, "json">
  75+        & FetchJson<
  76+          ApiSuccess,
  77+          ApiError extends unknown ? Ctx["_error"] : ApiError
  78+        >
  79+      >,
  80+    ): CreateAction<
  81+      & Omit<Ctx, "json">
  82+      & FetchJson<
  83+        ApiSuccess,
  84+        ApiError extends unknown ? Ctx["_error"] : ApiError
  85+      >,
  86+      ApiSuccess
  87+    >;
  88     get<P, ApiSuccess, ApiError = unknown>(
  89       req: { supervisor?: Supervisor },
  90       fn: MiddlewareApiCo<Ctx>,
  91     ): CreateActionWithPayload<
  92       & Omit<Ctx, "payload" | "json">
  93       & Payload<P>
  94-      & FetchJson<ApiSuccess, ApiError>,
  95-      P
  96+      & FetchJson<
  97+        ApiSuccess,
  98+        ApiError extends unknown ? Ctx["_error"] : ApiError
  99+      >,
 100+      P,
 101+      ApiSuccess
 102     >;
 103 
 104     /**
 105@@ -110,14 +155,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 106     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 107     post<P extends never, ApiSuccess, ApiError = unknown>(
 108       req: { supervisor?: Supervisor },
 109-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 110+    ): CreateAction<
 111+      & Omit<Ctx, "json">
 112+      & FetchJson<
 113+        ApiSuccess,
 114+        ApiError extends unknown ? Ctx["_error"] : ApiError
 115+      >,
 116+      ApiSuccess
 117+    >;
 118     post<P, ApiSuccess, ApiError = unknown>(req: {
 119       supervisor?: Supervisor;
 120     }): CreateActionWithPayload<
 121       & Omit<Ctx, "payload" | "json">
 122       & Payload<P>
 123-      & FetchJson<ApiSuccess, ApiError>,
 124-      P
 125+      & FetchJson<
 126+        ApiSuccess,
 127+        ApiError extends unknown ? Ctx["_error"] : ApiError
 128+      >,
 129+      P,
 130+      ApiSuccess
 131     >;
 132 
 133     /**
 134@@ -134,15 +190,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 135       fn: MiddlewareApiCo<Gtx>,
 136     ): CreateActionWithPayload<Gtx, P>;
 137     post<P extends never, ApiSuccess, ApiError = unknown>(
 138-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 139-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 140+      fn: MiddlewareApiCo<
 141+        & Omit<Ctx, "json">
 142+        & FetchJson<
 143+          ApiSuccess,
 144+          ApiError extends unknown ? Ctx["_error"] : ApiError
 145+        >
 146+      >,
 147+    ): CreateAction<
 148+      & Omit<Ctx, "json">
 149+      & FetchJson<
 150+        ApiSuccess,
 151+        ApiError extends unknown ? Ctx["_error"] : ApiError
 152+      >,
 153+      ApiSuccess
 154+    >;
 155     post<P, ApiSuccess, ApiError = unknown>(
 156       fn: MiddlewareApiCo<Ctx>,
 157     ): CreateActionWithPayload<
 158       & Omit<Ctx, "payload" | "json">
 159       & Payload<P>
 160-      & FetchJson<ApiSuccess, ApiError>,
 161-      P
 162+      & FetchJson<
 163+        ApiSuccess,
 164+        ApiError extends unknown ? Ctx["_error"] : ApiError
 165+      >,
 166+      P,
 167+      ApiSuccess
 168     >;
 169 
 170     /**
 171@@ -166,16 +239,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 172     ): CreateActionWithPayload<Gtx, P>;
 173     post<P extends never, ApiSuccess, ApiError = unknown>(
 174       req: { supervisor?: Supervisor },
 175-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 176-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 177+      fn: MiddlewareApiCo<
 178+        & Omit<Ctx, "json">
 179+        & FetchJson<
 180+          ApiSuccess,
 181+          ApiError extends unknown ? Ctx["_error"] : ApiError
 182+        >
 183+      >,
 184+    ): CreateAction<
 185+      & Omit<Ctx, "json">
 186+      & FetchJson<
 187+        ApiSuccess,
 188+        ApiError extends unknown ? Ctx["_error"] : ApiError
 189+      >,
 190+      ApiSuccess
 191+    >;
 192     post<P, ApiSuccess, ApiError = unknown>(
 193       req: { supervisor?: Supervisor },
 194       fn: MiddlewareApiCo<Ctx>,
 195     ): CreateActionWithPayload<
 196       & Omit<Ctx, "payload" | "json">
 197       & Payload<P>
 198-      & FetchJson<ApiSuccess, ApiError>,
 199-      P
 200+      & FetchJson<
 201+        ApiSuccess,
 202+        ApiError extends unknown ? Ctx["_error"] : ApiError
 203+      >,
 204+      P,
 205+      ApiSuccess
 206     >;
 207 
 208     /**
 209@@ -187,14 +277,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 210     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 211     put<P extends never, ApiSuccess, ApiError = unknown>(
 212       req: { supervisor?: Supervisor },
 213-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 214+    ): CreateAction<
 215+      & Omit<Ctx, "json">
 216+      & FetchJson<
 217+        ApiSuccess,
 218+        ApiError extends unknown ? Ctx["_error"] : ApiError
 219+      >,
 220+      ApiSuccess
 221+    >;
 222     put<P, ApiSuccess, ApiError = unknown>(req: {
 223       supervisor?: Supervisor;
 224     }): CreateActionWithPayload<
 225       & Omit<Ctx, "payload" | "json">
 226       & Payload<P>
 227-      & FetchJson<ApiSuccess, ApiError>,
 228-      P
 229+      & FetchJson<
 230+        ApiSuccess,
 231+        ApiError extends unknown ? Ctx["_error"] : ApiError
 232+      >,
 233+      P,
 234+      ApiSuccess
 235     >;
 236 
 237     /**
 238@@ -211,15 +312,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 239       fn: MiddlewareApiCo<Gtx>,
 240     ): CreateActionWithPayload<Gtx, P>;
 241     put<P extends never, ApiSuccess, ApiError = unknown>(
 242-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 243-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 244+      fn: MiddlewareApiCo<
 245+        & Omit<Ctx, "json">
 246+        & FetchJson<
 247+          ApiSuccess,
 248+          ApiError extends unknown ? Ctx["_error"] : ApiError
 249+        >
 250+      >,
 251+    ): CreateAction<
 252+      & Omit<Ctx, "json">
 253+      & FetchJson<
 254+        ApiSuccess,
 255+        ApiError extends unknown ? Ctx["_error"] : ApiError
 256+      >,
 257+      ApiSuccess
 258+    >;
 259     put<P, ApiSuccess, ApiError = unknown>(
 260       fn: MiddlewareApiCo<Ctx>,
 261     ): CreateActionWithPayload<
 262       & Omit<Ctx, "payload" | "json">
 263       & Payload<P>
 264-      & FetchJson<ApiSuccess, ApiError>,
 265-      P
 266+      & FetchJson<
 267+        ApiSuccess,
 268+        ApiError extends unknown ? Ctx["_error"] : ApiError
 269+      >,
 270+      P,
 271+      ApiSuccess
 272     >;
 273 
 274     /**
 275@@ -243,16 +361,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 276     ): CreateActionWithPayload<Gtx, P>;
 277     put<P extends never, ApiSuccess, ApiError = unknown>(
 278       req: { supervisor?: Supervisor },
 279-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 280-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 281+      fn: MiddlewareApiCo<
 282+        & Omit<Ctx, "json">
 283+        & FetchJson<
 284+          ApiSuccess,
 285+          ApiError extends unknown ? Ctx["_error"] : ApiError
 286+        >
 287+      >,
 288+    ): CreateAction<
 289+      & Omit<Ctx, "json">
 290+      & FetchJson<
 291+        ApiSuccess,
 292+        ApiError extends unknown ? Ctx["_error"] : ApiError
 293+      >,
 294+      ApiSuccess
 295+    >;
 296     put<P, ApiSuccess, ApiError = unknown>(
 297       req: { supervisor?: Supervisor },
 298       fn: MiddlewareApiCo<Ctx>,
 299     ): CreateActionWithPayload<
 300       & Omit<Ctx, "payload" | "json">
 301       & Payload<P>
 302-      & FetchJson<ApiSuccess, ApiError>,
 303-      P
 304+      & FetchJson<
 305+        ApiSuccess,
 306+        ApiError extends unknown ? Ctx["_error"] : ApiError
 307+      >,
 308+      P,
 309+      ApiSuccess
 310     >;
 311 
 312     /**
 313@@ -264,14 +399,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 314     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 315     patch<P extends never, ApiSuccess, ApiError = unknown>(
 316       req: { supervisor?: Supervisor },
 317-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 318+    ): CreateAction<
 319+      & Omit<Ctx, "json">
 320+      & FetchJson<
 321+        ApiSuccess,
 322+        ApiError extends unknown ? Ctx["_error"] : ApiError
 323+      >,
 324+      ApiSuccess
 325+    >;
 326     patch<P, ApiSuccess, ApiError = unknown>(req: {
 327       supervisor?: Supervisor;
 328     }): CreateActionWithPayload<
 329       & Omit<Ctx, "payload" | "json">
 330       & Payload<P>
 331-      & FetchJson<ApiSuccess, ApiError>,
 332-      P
 333+      & FetchJson<
 334+        ApiSuccess,
 335+        ApiError extends unknown ? Ctx["_error"] : ApiError
 336+      >,
 337+      P,
 338+      ApiSuccess
 339     >;
 340 
 341     /**
 342@@ -288,15 +434,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 343       fn: MiddlewareApiCo<Gtx>,
 344     ): CreateActionWithPayload<Gtx, P>;
 345     patch<P extends never, ApiSuccess, ApiError = unknown>(
 346-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 347-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 348+      fn: MiddlewareApiCo<
 349+        & Omit<Ctx, "json">
 350+        & FetchJson<
 351+          ApiSuccess,
 352+          ApiError extends unknown ? Ctx["_error"] : ApiError
 353+        >
 354+      >,
 355+    ): CreateAction<
 356+      & Omit<Ctx, "json">
 357+      & FetchJson<
 358+        ApiSuccess,
 359+        ApiError extends unknown ? Ctx["_error"] : ApiError
 360+      >,
 361+      ApiSuccess
 362+    >;
 363     patch<P, ApiSuccess, ApiError = unknown>(
 364       fn: MiddlewareApiCo<Ctx>,
 365     ): CreateActionWithPayload<
 366       & Omit<Ctx, "payload" | "json">
 367       & Payload<P>
 368-      & FetchJson<ApiSuccess, ApiError>,
 369-      P
 370+      & FetchJson<
 371+        ApiSuccess,
 372+        ApiError extends unknown ? Ctx["_error"] : ApiError
 373+      >,
 374+      P,
 375+      ApiSuccess
 376     >;
 377 
 378     /**
 379@@ -320,16 +483,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 380     ): CreateActionWithPayload<Gtx, P>;
 381     patch<P extends never, ApiSuccess, ApiError = unknown>(
 382       req: { supervisor?: Supervisor },
 383-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 384-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 385+      fn: MiddlewareApiCo<
 386+        & Omit<Ctx, "json">
 387+        & FetchJson<
 388+          ApiSuccess,
 389+          ApiError extends unknown ? Ctx["_error"] : ApiError
 390+        >
 391+      >,
 392+    ): CreateAction<
 393+      & Omit<Ctx, "json">
 394+      & FetchJson<
 395+        ApiSuccess,
 396+        ApiError extends unknown ? Ctx["_error"] : ApiError
 397+      >,
 398+      ApiSuccess
 399+    >;
 400     patch<P, ApiSuccess, ApiError = unknown>(
 401       req: { supervisor?: Supervisor },
 402       fn: MiddlewareApiCo<Ctx>,
 403     ): CreateActionWithPayload<
 404       & Omit<Ctx, "payload" | "json">
 405       & Payload<P>
 406-      & FetchJson<ApiSuccess, ApiError>,
 407-      P
 408+      & FetchJson<
 409+        ApiSuccess,
 410+        ApiError extends unknown ? Ctx["_error"] : ApiError
 411+      >,
 412+      P,
 413+      ApiSuccess
 414     >;
 415 
 416     /**
 417@@ -341,14 +521,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 418     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 419     delete<P extends never, ApiSuccess, ApiError = unknown>(
 420       req: { supervisor?: Supervisor },
 421-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 422+    ): CreateAction<
 423+      & Omit<Ctx, "json">
 424+      & FetchJson<
 425+        ApiSuccess,
 426+        ApiError extends unknown ? Ctx["_error"] : ApiError
 427+      >,
 428+      ApiSuccess
 429+    >;
 430     delete<P, ApiSuccess, ApiError = unknown>(req: {
 431       supervisor?: Supervisor;
 432     }): CreateActionWithPayload<
 433       & Omit<Ctx, "payload" | "json">
 434       & Payload<P>
 435-      & FetchJson<ApiSuccess, ApiError>,
 436-      P
 437+      & FetchJson<
 438+        ApiSuccess,
 439+        ApiError extends unknown ? Ctx["_error"] : ApiError
 440+      >,
 441+      P,
 442+      ApiSuccess
 443     >;
 444 
 445     /**
 446@@ -365,15 +556,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 447       fn: MiddlewareApiCo<Gtx>,
 448     ): CreateActionWithPayload<Gtx, P>;
 449     delete<P extends never, ApiSuccess, ApiError = unknown>(
 450-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 451-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 452+      fn: MiddlewareApiCo<
 453+        & Omit<Ctx, "json">
 454+        & FetchJson<
 455+          ApiSuccess,
 456+          ApiError extends unknown ? Ctx["_error"] : ApiError
 457+        >
 458+      >,
 459+    ): CreateAction<
 460+      & Omit<Ctx, "json">
 461+      & FetchJson<
 462+        ApiSuccess,
 463+        ApiError extends unknown ? Ctx["_error"] : ApiError
 464+      >,
 465+      ApiSuccess
 466+    >;
 467     delete<P, ApiSuccess, ApiError = unknown>(
 468       fn: MiddlewareApiCo<Ctx>,
 469     ): CreateActionWithPayload<
 470       & Omit<Ctx, "payload" | "json">
 471       & Payload<P>
 472-      & FetchJson<ApiSuccess, ApiError>,
 473-      P
 474+      & FetchJson<
 475+        ApiSuccess,
 476+        ApiError extends unknown ? Ctx["_error"] : ApiError
 477+      >,
 478+      P,
 479+      ApiSuccess
 480     >;
 481 
 482     /**
 483@@ -397,16 +605,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 484     ): CreateActionWithPayload<Gtx, P>;
 485     delete<P extends never, ApiSuccess, ApiError = unknown>(
 486       req: { supervisor?: Supervisor },
 487-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 488-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 489+      fn: MiddlewareApiCo<
 490+        & Omit<Ctx, "json">
 491+        & FetchJson<
 492+          ApiSuccess,
 493+          ApiError extends unknown ? Ctx["_error"] : ApiError
 494+        >
 495+      >,
 496+    ): CreateAction<
 497+      & Omit<Ctx, "json">
 498+      & FetchJson<
 499+        ApiSuccess,
 500+        ApiError extends unknown ? Ctx["_error"] : ApiError
 501+      >,
 502+      ApiSuccess
 503+    >;
 504     delete<P, ApiSuccess, ApiError = unknown>(
 505       req: { supervisor?: Supervisor },
 506       fn: MiddlewareApiCo<Ctx>,
 507     ): CreateActionWithPayload<
 508       & Omit<Ctx, "payload" | "json">
 509       & Payload<P>
 510-      & FetchJson<ApiSuccess, ApiError>,
 511-      P
 512+      & FetchJson<
 513+        ApiSuccess,
 514+        ApiError extends unknown ? Ctx["_error"] : ApiError
 515+      >,
 516+      P,
 517+      ApiSuccess
 518     >;
 519 
 520     /**
 521@@ -418,14 +643,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 522     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 523     options<P extends never, ApiSuccess, ApiError = unknown>(
 524       req: { supervisor?: Supervisor },
 525-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 526+    ): CreateAction<
 527+      & Omit<Ctx, "json">
 528+      & FetchJson<
 529+        ApiSuccess,
 530+        ApiError extends unknown ? Ctx["_error"] : ApiError
 531+      >,
 532+      ApiSuccess
 533+    >;
 534     options<P, ApiSuccess, ApiError = unknown>(req: {
 535       supervisor?: Supervisor;
 536     }): CreateActionWithPayload<
 537       & Omit<Ctx, "payload" | "json">
 538       & Payload<P>
 539-      & FetchJson<ApiSuccess, ApiError>,
 540-      P
 541+      & FetchJson<
 542+        ApiSuccess,
 543+        ApiError extends unknown ? Ctx["_error"] : ApiError
 544+      >,
 545+      P,
 546+      ApiSuccess
 547     >;
 548 
 549     /**
 550@@ -442,15 +678,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 551       fn: MiddlewareApiCo<Gtx>,
 552     ): CreateActionWithPayload<Gtx, P>;
 553     options<P extends never, ApiSuccess, ApiError = unknown>(
 554-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 555-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 556+      fn: MiddlewareApiCo<
 557+        & Omit<Ctx, "json">
 558+        & FetchJson<
 559+          ApiSuccess,
 560+          ApiError extends unknown ? Ctx["_error"] : ApiError
 561+        >
 562+      >,
 563+    ): CreateAction<
 564+      & Omit<Ctx, "json">
 565+      & FetchJson<
 566+        ApiSuccess,
 567+        ApiError extends unknown ? Ctx["_error"] : ApiError
 568+      >,
 569+      ApiSuccess
 570+    >;
 571     options<P, ApiSuccess, ApiError = unknown>(
 572       fn: MiddlewareApiCo<Ctx>,
 573     ): CreateActionWithPayload<
 574       & Omit<Ctx, "payload" | "json">
 575       & Payload<P>
 576-      & FetchJson<ApiSuccess, ApiError>,
 577-      P
 578+      & FetchJson<
 579+        ApiSuccess,
 580+        ApiError extends unknown ? Ctx["_error"] : ApiError
 581+      >,
 582+      P,
 583+      ApiSuccess
 584     >;
 585 
 586     /**
 587@@ -474,16 +727,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 588     ): CreateActionWithPayload<Gtx, P>;
 589     options<P extends never, ApiSuccess, ApiError = unknown>(
 590       req: { supervisor?: Supervisor },
 591-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 592-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 593+      fn: MiddlewareApiCo<
 594+        & Omit<Ctx, "json">
 595+        & FetchJson<
 596+          ApiSuccess,
 597+          ApiError extends unknown ? Ctx["_error"] : ApiError
 598+        >
 599+      >,
 600+    ): CreateAction<
 601+      & Omit<Ctx, "json">
 602+      & FetchJson<
 603+        ApiSuccess,
 604+        ApiError extends unknown ? Ctx["_error"] : ApiError
 605+      >,
 606+      ApiSuccess
 607+    >;
 608     options<P, ApiSuccess, ApiError = unknown>(
 609       req: { supervisor?: Supervisor },
 610       fn: MiddlewareApiCo<Ctx>,
 611     ): CreateActionWithPayload<
 612       & Omit<Ctx, "payload" | "json">
 613       & Payload<P>
 614-      & FetchJson<ApiSuccess, ApiError>,
 615-      P
 616+      & FetchJson<
 617+        ApiSuccess,
 618+        ApiError extends unknown ? Ctx["_error"] : ApiError
 619+      >,
 620+      P,
 621+      ApiSuccess
 622     >;
 623 
 624     /**
 625@@ -495,14 +765,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 626     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 627     head<P extends never, ApiSuccess, ApiError = unknown>(
 628       req: { supervisor?: Supervisor },
 629-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 630+    ): CreateAction<
 631+      & Omit<Ctx, "json">
 632+      & FetchJson<
 633+        ApiSuccess,
 634+        ApiError extends unknown ? Ctx["_error"] : ApiError
 635+      >,
 636+      ApiSuccess
 637+    >;
 638     head<P, ApiSuccess, ApiError = unknown>(req: {
 639       supervisor?: Supervisor;
 640     }): CreateActionWithPayload<
 641       & Omit<Ctx, "payload" | "json">
 642       & Payload<P>
 643-      & FetchJson<ApiSuccess, ApiError>,
 644-      P
 645+      & FetchJson<
 646+        ApiSuccess,
 647+        ApiError extends unknown ? Ctx["_error"] : ApiError
 648+      >,
 649+      P,
 650+      ApiSuccess
 651     >;
 652 
 653     /**
 654@@ -519,15 +800,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 655       fn: MiddlewareApiCo<Gtx>,
 656     ): CreateActionWithPayload<Gtx, P>;
 657     head<P extends never, ApiSuccess, ApiError = unknown>(
 658-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 659-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 660+      fn: MiddlewareApiCo<
 661+        & Omit<Ctx, "json">
 662+        & FetchJson<
 663+          ApiSuccess,
 664+          ApiError extends unknown ? Ctx["_error"] : ApiError
 665+        >
 666+      >,
 667+    ): CreateAction<
 668+      & Omit<Ctx, "json">
 669+      & FetchJson<
 670+        ApiSuccess,
 671+        ApiError extends unknown ? Ctx["_error"] : ApiError
 672+      >,
 673+      ApiSuccess
 674+    >;
 675     head<P, ApiSuccess, ApiError = unknown>(
 676       fn: MiddlewareApiCo<Ctx>,
 677     ): CreateActionWithPayload<
 678       & Omit<Ctx, "payload" | "json">
 679       & Payload<P>
 680-      & FetchJson<ApiSuccess, ApiError>,
 681-      P
 682+      & FetchJson<
 683+        ApiSuccess,
 684+        ApiError extends unknown ? Ctx["_error"] : ApiError
 685+      >,
 686+      P,
 687+      ApiSuccess
 688     >;
 689 
 690     /**
 691@@ -551,16 +849,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 692     ): CreateActionWithPayload<Gtx, P>;
 693     head<P extends never, ApiSuccess, ApiError = unknown>(
 694       req: { supervisor?: Supervisor },
 695-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 696-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 697+      fn: MiddlewareApiCo<
 698+        & Omit<Ctx, "json">
 699+        & FetchJson<
 700+          ApiSuccess,
 701+          ApiError extends unknown ? Ctx["_error"] : ApiError
 702+        >
 703+      >,
 704+    ): CreateAction<
 705+      & Omit<Ctx, "json">
 706+      & FetchJson<
 707+        ApiSuccess,
 708+        ApiError extends unknown ? Ctx["_error"] : ApiError
 709+      >,
 710+      ApiSuccess
 711+    >;
 712     head<P, ApiSuccess, ApiError = unknown>(
 713       req: { supervisor?: Supervisor },
 714       fn: MiddlewareApiCo<Ctx>,
 715     ): CreateActionWithPayload<
 716       & Omit<Ctx, "payload" | "json">
 717       & Payload<P>
 718-      & FetchJson<ApiSuccess, ApiError>,
 719-      P
 720+      & FetchJson<
 721+        ApiSuccess,
 722+        ApiError extends unknown ? Ctx["_error"] : ApiError
 723+      >,
 724+      P,
 725+      ApiSuccess
 726     >;
 727 
 728     /**
 729@@ -572,14 +887,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 730     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 731     connect<P extends never, ApiSuccess, ApiError = unknown>(
 732       req: { supervisor?: Supervisor },
 733-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 734+    ): CreateAction<
 735+      & Omit<Ctx, "json">
 736+      & FetchJson<
 737+        ApiSuccess,
 738+        ApiError extends unknown ? Ctx["_error"] : ApiError
 739+      >,
 740+      ApiSuccess
 741+    >;
 742     connect<P, ApiSuccess, ApiError = unknown>(req: {
 743       supervisor?: Supervisor;
 744     }): CreateActionWithPayload<
 745       & Omit<Ctx, "payload" | "json">
 746       & Payload<P>
 747-      & FetchJson<ApiSuccess, ApiError>,
 748-      P
 749+      & FetchJson<
 750+        ApiSuccess,
 751+        ApiError extends unknown ? Ctx["_error"] : ApiError
 752+      >,
 753+      P,
 754+      ApiSuccess
 755     >;
 756 
 757     /**
 758@@ -596,15 +922,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 759       fn: MiddlewareApiCo<Gtx>,
 760     ): CreateActionWithPayload<Gtx, P>;
 761     connect<P extends never, ApiSuccess, ApiError = unknown>(
 762-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 763-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 764+      fn: MiddlewareApiCo<
 765+        & Omit<Ctx, "json">
 766+        & FetchJson<
 767+          ApiSuccess,
 768+          ApiError extends unknown ? Ctx["_error"] : ApiError
 769+        >
 770+      >,
 771+    ): CreateAction<
 772+      & Omit<Ctx, "json">
 773+      & FetchJson<
 774+        ApiSuccess,
 775+        ApiError extends unknown ? Ctx["_error"] : ApiError
 776+      >,
 777+      ApiSuccess
 778+    >;
 779     connect<P, ApiSuccess, ApiError = unknown>(
 780       fn: MiddlewareApiCo<Ctx>,
 781     ): CreateActionWithPayload<
 782       & Omit<Ctx, "payload" | "json">
 783       & Payload<P>
 784-      & FetchJson<ApiSuccess, ApiError>,
 785-      P
 786+      & FetchJson<
 787+        ApiSuccess,
 788+        ApiError extends unknown ? Ctx["_error"] : ApiError
 789+      >,
 790+      P,
 791+      ApiSuccess
 792     >;
 793 
 794     /**
 795@@ -628,16 +971,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 796     ): CreateActionWithPayload<Gtx, P>;
 797     connect<P extends never, ApiSuccess, ApiError = unknown>(
 798       req: { supervisor?: Supervisor },
 799-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 800-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 801+      fn: MiddlewareApiCo<
 802+        & Omit<Ctx, "json">
 803+        & FetchJson<
 804+          ApiSuccess,
 805+          ApiError extends unknown ? Ctx["_error"] : ApiError
 806+        >
 807+      >,
 808+    ): CreateAction<
 809+      & Omit<Ctx, "json">
 810+      & FetchJson<
 811+        ApiSuccess,
 812+        ApiError extends unknown ? Ctx["_error"] : ApiError
 813+      >,
 814+      ApiSuccess
 815+    >;
 816     connect<P, ApiSuccess, ApiError = unknown>(
 817       req: { supervisor?: Supervisor },
 818       fn: MiddlewareApiCo<Ctx>,
 819     ): CreateActionWithPayload<
 820       & Omit<Ctx, "payload" | "json">
 821       & Payload<P>
 822-      & FetchJson<ApiSuccess, ApiError>,
 823-      P
 824+      & FetchJson<
 825+        ApiSuccess,
 826+        ApiError extends unknown ? Ctx["_error"] : ApiError
 827+      >,
 828+      P,
 829+      ApiSuccess
 830     >;
 831 
 832     /**
 833@@ -649,14 +1009,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 834     ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 835     trace<P extends never, ApiSuccess, ApiError = unknown>(
 836       req: { supervisor?: Supervisor },
 837-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 838+    ): CreateAction<
 839+      & Omit<Ctx, "json">
 840+      & FetchJson<
 841+        ApiSuccess,
 842+        ApiError extends unknown ? Ctx["_error"] : ApiError
 843+      >,
 844+      ApiSuccess
 845+    >;
 846     trace<P, ApiSuccess, ApiError = unknown>(req: {
 847       supervisor?: Supervisor;
 848     }): CreateActionWithPayload<
 849       & Omit<Ctx, "payload" | "json">
 850       & Payload<P>
 851-      & FetchJson<ApiSuccess, ApiError>,
 852-      P
 853+      & FetchJson<
 854+        ApiSuccess,
 855+        ApiError extends unknown ? Ctx["_error"] : ApiError
 856+      >,
 857+      P,
 858+      ApiSuccess
 859     >;
 860 
 861     /**
 862@@ -673,15 +1044,32 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 863       fn: MiddlewareApiCo<Gtx>,
 864     ): CreateActionWithPayload<Gtx, P>;
 865     trace<P extends never, ApiSuccess, ApiError = unknown>(
 866-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 867-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 868+      fn: MiddlewareApiCo<
 869+        & Omit<Ctx, "json">
 870+        & FetchJson<
 871+          ApiSuccess,
 872+          ApiError extends unknown ? Ctx["_error"] : ApiError
 873+        >
 874+      >,
 875+    ): CreateAction<
 876+      & Omit<Ctx, "json">
 877+      & FetchJson<
 878+        ApiSuccess,
 879+        ApiError extends unknown ? Ctx["_error"] : ApiError
 880+      >,
 881+      ApiSuccess
 882+    >;
 883     trace<P, ApiSuccess, ApiError = unknown>(
 884       fn: MiddlewareApiCo<Ctx>,
 885     ): CreateActionWithPayload<
 886       & Omit<Ctx, "payload" | "json">
 887       & Payload<P>
 888-      & FetchJson<ApiSuccess, ApiError>,
 889-      P
 890+      & FetchJson<
 891+        ApiSuccess,
 892+        ApiError extends unknown ? Ctx["_error"] : ApiError
 893+      >,
 894+      P,
 895+      ApiSuccess
 896     >;
 897 
 898     /**
 899@@ -705,16 +1093,33 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 900     ): CreateActionWithPayload<Gtx, P>;
 901     trace<P extends never, ApiSuccess, ApiError = unknown>(
 902       req: { supervisor?: Supervisor },
 903-      fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
 904-    ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 905+      fn: MiddlewareApiCo<
 906+        & Omit<Ctx, "json">
 907+        & FetchJson<
 908+          ApiSuccess,
 909+          ApiError extends unknown ? Ctx["_error"] : ApiError
 910+        >
 911+      >,
 912+    ): CreateAction<
 913+      & Omit<Ctx, "json">
 914+      & FetchJson<
 915+        ApiSuccess,
 916+        ApiError extends unknown ? Ctx["_error"] : ApiError
 917+      >,
 918+      ApiSuccess
 919+    >;
 920     trace<P, ApiSuccess, ApiError = unknown>(
 921       req: { supervisor?: Supervisor },
 922       fn: MiddlewareApiCo<Ctx>,
 923     ): CreateActionWithPayload<
 924       & Omit<Ctx, "payload" | "json">
 925       & Payload<P>
 926-      & FetchJson<ApiSuccess, ApiError>,
 927-      P
 928+      & FetchJson<
 929+        ApiSuccess,
 930+        ApiError extends unknown ? Ctx["_error"] : ApiError
 931+      >,
 932+      P,
 933+      ApiSuccess
 934     >;
 935   };
 936 
 937@@ -727,14 +1132,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 938   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
 939   get<P extends never, ApiSuccess, ApiError = unknown>(
 940     name: ApiName,
 941-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 942+  ): CreateAction<
 943+    & Omit<Ctx, "json">
 944+    & FetchJson<
 945+      ApiSuccess,
 946+      ApiError extends unknown ? Ctx["_error"] : ApiError
 947+    >,
 948+    ApiSuccess
 949+  >;
 950   get<P, ApiSuccess, ApiError = unknown>(
 951     name: ApiName,
 952   ): CreateActionWithPayload<
 953     & Omit<Ctx, "payload" | "json">
 954     & Payload<P>
 955-    & FetchJson<ApiSuccess, ApiError>,
 956-    P
 957+    & FetchJson<
 958+      ApiSuccess,
 959+      ApiError extends unknown ? Ctx["_error"] : ApiError
 960+    >,
 961+    P,
 962+    ApiSuccess
 963   >;
 964 
 965   /**
 966@@ -752,15 +1168,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 967   get<P extends never, ApiSuccess, ApiError = unknown>(
 968     name: ApiName,
 969     req: { supervisor?: Supervisor },
 970-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
 971+  ): CreateAction<
 972+    & Omit<Ctx, "json">
 973+    & FetchJson<
 974+      ApiSuccess,
 975+      ApiError extends unknown ? Ctx["_error"] : ApiError
 976+    >,
 977+    ApiSuccess
 978+  >;
 979   get<P, ApiSuccess, ApiError = unknown>(
 980     name: ApiName,
 981     req: { supervisor?: Supervisor },
 982   ): CreateActionWithPayload<
 983     & Omit<Ctx, "payload" | "json">
 984     & Payload<P>
 985-    & FetchJson<ApiSuccess, ApiError>,
 986-    P
 987+    & FetchJson<
 988+      ApiSuccess,
 989+      ApiError extends unknown ? Ctx["_error"] : ApiError
 990+    >,
 991+    P,
 992+    ApiSuccess
 993   >;
 994 
 995   /**
 996@@ -781,20 +1208,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
 997   ): CreateActionWithPayload<Gtx, P>;
 998   get<P extends never, ApiSuccess, ApiError = unknown>(
 999     name: ApiName,
1000-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1001-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1002+    fn: MiddlewareApiCo<
1003+      & Omit<Ctx, "json">
1004+      & FetchJson<
1005+        ApiSuccess,
1006+        ApiError extends unknown ? Ctx["_error"] : ApiError
1007+      >
1008+    >,
1009+  ): CreateAction<
1010+    & Omit<Ctx, "json">
1011+    & FetchJson<
1012+      ApiSuccess,
1013+      ApiError extends unknown ? Ctx["_error"] : ApiError
1014+    >,
1015+    ApiSuccess
1016+  >;
1017   get<P, ApiSuccess, ApiError = unknown>(
1018     name: ApiName,
1019     fn: MiddlewareApiCo<
1020       & Omit<Ctx, "payload" | "json">
1021       & Payload<P>
1022-      & FetchJson<ApiSuccess, ApiError>
1023+      & FetchJson<
1024+        ApiSuccess,
1025+        ApiError extends unknown ? Ctx["_error"] : ApiError
1026+      >
1027     >,
1028   ): CreateActionWithPayload<
1029     & Omit<Ctx, "payload" | "json">
1030     & Payload<P>
1031-    & FetchJson<ApiSuccess, ApiError>,
1032-    P
1033+    & FetchJson<
1034+      ApiSuccess,
1035+      ApiError extends unknown ? Ctx["_error"] : ApiError
1036+    >,
1037+    P,
1038+    ApiSuccess
1039   >;
1040 
1041   /**
1042@@ -823,21 +1270,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1043   get<P extends never, ApiSuccess, ApiError = unknown>(
1044     name: ApiName,
1045     req: { supervisor?: Supervisor },
1046-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1047-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1048+    fn: MiddlewareApiCo<
1049+      & Omit<Ctx, "json">
1050+      & FetchJson<
1051+        ApiSuccess,
1052+        ApiError extends unknown ? Ctx["_error"] : ApiError
1053+      >
1054+    >,
1055+  ): CreateAction<
1056+    & Omit<Ctx, "json">
1057+    & FetchJson<
1058+      ApiSuccess,
1059+      ApiError extends unknown ? Ctx["_error"] : ApiError
1060+    >,
1061+    ApiSuccess
1062+  >;
1063   get<P, ApiSuccess, ApiError = unknown>(
1064     name: ApiName,
1065     req: { supervisor?: Supervisor },
1066     fn: MiddlewareApiCo<
1067       & Omit<Ctx, "payload" | "json">
1068       & Payload<P>
1069-      & FetchJson<ApiSuccess, ApiError>
1070+      & FetchJson<
1071+        ApiSuccess,
1072+        ApiError extends unknown ? Ctx["_error"] : ApiError
1073+      >
1074     >,
1075   ): CreateActionWithPayload<
1076     & Omit<Ctx, "payload" | "json">
1077     & Payload<P>
1078-    & FetchJson<ApiSuccess, ApiError>,
1079-    P
1080+    & FetchJson<
1081+      ApiSuccess,
1082+      ApiError extends unknown ? Ctx["_error"] : ApiError
1083+    >,
1084+    P,
1085+    ApiSuccess
1086   >;
1087 
1088   /**
1089@@ -849,14 +1316,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1090   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1091   post<P extends never, ApiSuccess, ApiError = unknown>(
1092     name: ApiName,
1093-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1094+  ): CreateAction<
1095+    & Omit<Ctx, "json">
1096+    & FetchJson<
1097+      ApiSuccess,
1098+      ApiError extends unknown ? Ctx["_error"] : ApiError
1099+    >,
1100+    ApiSuccess
1101+  >;
1102   post<P, ApiSuccess, ApiError = unknown>(
1103     name: ApiName,
1104   ): CreateActionWithPayload<
1105     & Omit<Ctx, "payload" | "json">
1106     & Payload<P>
1107-    & FetchJson<ApiSuccess, ApiError>,
1108-    P
1109+    & FetchJson<
1110+      ApiSuccess,
1111+      ApiError extends unknown ? Ctx["_error"] : ApiError
1112+    >,
1113+    P,
1114+    ApiSuccess
1115   >;
1116 
1117   /**
1118@@ -874,15 +1352,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1119   post<P extends never, ApiSuccess, ApiError = unknown>(
1120     name: ApiName,
1121     req: { supervisor?: Supervisor },
1122-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1123+  ): CreateAction<
1124+    & Omit<Ctx, "json">
1125+    & FetchJson<
1126+      ApiSuccess,
1127+      ApiError extends unknown ? Ctx["_error"] : ApiError
1128+    >,
1129+    ApiSuccess
1130+  >;
1131   post<P, ApiSuccess, ApiError = unknown>(
1132     name: ApiName,
1133     req: { supervisor?: Supervisor },
1134   ): CreateActionWithPayload<
1135     & Omit<Ctx, "payload" | "json">
1136     & Payload<P>
1137-    & FetchJson<ApiSuccess, ApiError>,
1138-    P
1139+    & FetchJson<
1140+      ApiSuccess,
1141+      ApiError extends unknown ? Ctx["_error"] : ApiError
1142+    >,
1143+    P,
1144+    ApiSuccess
1145   >;
1146 
1147   /**
1148@@ -903,20 +1392,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1149   ): CreateActionWithPayload<Gtx, P>;
1150   post<P extends never, ApiSuccess, ApiError = unknown>(
1151     name: ApiName,
1152-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1153-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1154+    fn: MiddlewareApiCo<
1155+      & Omit<Ctx, "json">
1156+      & FetchJson<
1157+        ApiSuccess,
1158+        ApiError extends unknown ? Ctx["_error"] : ApiError
1159+      >
1160+    >,
1161+  ): CreateAction<
1162+    & Omit<Ctx, "json">
1163+    & FetchJson<
1164+      ApiSuccess,
1165+      ApiError extends unknown ? Ctx["_error"] : ApiError
1166+    >,
1167+    ApiSuccess
1168+  >;
1169   post<P, ApiSuccess, ApiError = unknown>(
1170     name: ApiName,
1171     fn: MiddlewareApiCo<
1172       & Omit<Ctx, "payload" | "json">
1173       & Payload<P>
1174-      & FetchJson<ApiSuccess, ApiError>
1175+      & FetchJson<
1176+        ApiSuccess,
1177+        ApiError extends unknown ? Ctx["_error"] : ApiError
1178+      >
1179     >,
1180   ): CreateActionWithPayload<
1181     & Omit<Ctx, "payload" | "json">
1182     & Payload<P>
1183-    & FetchJson<ApiSuccess, ApiError>,
1184-    P
1185+    & FetchJson<
1186+      ApiSuccess,
1187+      ApiError extends unknown ? Ctx["_error"] : ApiError
1188+    >,
1189+    P,
1190+    ApiSuccess
1191   >;
1192 
1193   /**
1194@@ -945,21 +1454,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1195   post<P extends never, ApiSuccess, ApiError = unknown>(
1196     name: ApiName,
1197     req: { supervisor?: Supervisor },
1198-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1199-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1200+    fn: MiddlewareApiCo<
1201+      & Omit<Ctx, "json">
1202+      & FetchJson<
1203+        ApiSuccess,
1204+        ApiError extends unknown ? Ctx["_error"] : ApiError
1205+      >
1206+    >,
1207+  ): CreateAction<
1208+    & Omit<Ctx, "json">
1209+    & FetchJson<
1210+      ApiSuccess,
1211+      ApiError extends unknown ? Ctx["_error"] : ApiError
1212+    >,
1213+    ApiSuccess
1214+  >;
1215   post<P, ApiSuccess, ApiError = unknown>(
1216     name: ApiName,
1217     req: { supervisor?: Supervisor },
1218     fn: MiddlewareApiCo<
1219       & Omit<Ctx, "payload" | "json">
1220       & Payload<P>
1221-      & FetchJson<ApiSuccess, ApiError>
1222+      & FetchJson<
1223+        ApiSuccess,
1224+        ApiError extends unknown ? Ctx["_error"] : ApiError
1225+      >
1226     >,
1227   ): CreateActionWithPayload<
1228     & Omit<Ctx, "payload" | "json">
1229     & Payload<P>
1230-    & FetchJson<ApiSuccess, ApiError>,
1231-    P
1232+    & FetchJson<
1233+      ApiSuccess,
1234+      ApiError extends unknown ? Ctx["_error"] : ApiError
1235+    >,
1236+    P,
1237+    ApiSuccess
1238   >;
1239 
1240   /**
1241@@ -971,14 +1500,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1242   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1243   put<P extends never, ApiSuccess, ApiError = unknown>(
1244     name: ApiName,
1245-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1246+  ): CreateAction<
1247+    & Omit<Ctx, "json">
1248+    & FetchJson<
1249+      ApiSuccess,
1250+      ApiError extends unknown ? Ctx["_error"] : ApiError
1251+    >,
1252+    ApiSuccess
1253+  >;
1254   put<P, ApiSuccess, ApiError = unknown>(
1255     name: ApiName,
1256   ): CreateActionWithPayload<
1257     & Omit<Ctx, "payload" | "json">
1258     & Payload<P>
1259-    & FetchJson<ApiSuccess, ApiError>,
1260-    P
1261+    & FetchJson<
1262+      ApiSuccess,
1263+      ApiError extends unknown ? Ctx["_error"] : ApiError
1264+    >,
1265+    P,
1266+    ApiSuccess
1267   >;
1268 
1269   /**
1270@@ -996,15 +1536,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1271   put<P extends never, ApiSuccess, ApiError = unknown>(
1272     name: ApiName,
1273     req: { supervisor?: Supervisor },
1274-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1275+  ): CreateAction<
1276+    & Omit<Ctx, "json">
1277+    & FetchJson<
1278+      ApiSuccess,
1279+      ApiError extends unknown ? Ctx["_error"] : ApiError
1280+    >,
1281+    ApiSuccess
1282+  >;
1283   put<P, ApiSuccess, ApiError = unknown>(
1284     name: ApiName,
1285     req: { supervisor?: Supervisor },
1286   ): CreateActionWithPayload<
1287     & Omit<Ctx, "payload" | "json">
1288     & Payload<P>
1289-    & FetchJson<ApiSuccess, ApiError>,
1290-    P
1291+    & FetchJson<
1292+      ApiSuccess,
1293+      ApiError extends unknown ? Ctx["_error"] : ApiError
1294+    >,
1295+    P,
1296+    ApiSuccess
1297   >;
1298 
1299   /**
1300@@ -1025,20 +1576,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1301   ): CreateActionWithPayload<Gtx, P>;
1302   put<P extends never, ApiSuccess, ApiError = unknown>(
1303     name: ApiName,
1304-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1305-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1306+    fn: MiddlewareApiCo<
1307+      & Omit<Ctx, "json">
1308+      & FetchJson<
1309+        ApiSuccess,
1310+        ApiError extends unknown ? Ctx["_error"] : ApiError
1311+      >
1312+    >,
1313+  ): CreateAction<
1314+    & Omit<Ctx, "json">
1315+    & FetchJson<
1316+      ApiSuccess,
1317+      ApiError extends unknown ? Ctx["_error"] : ApiError
1318+    >,
1319+    ApiSuccess
1320+  >;
1321   put<P, ApiSuccess, ApiError = unknown>(
1322     name: ApiName,
1323     fn: MiddlewareApiCo<
1324       & Omit<Ctx, "payload" | "json">
1325       & Payload<P>
1326-      & FetchJson<ApiSuccess, ApiError>
1327+      & FetchJson<
1328+        ApiSuccess,
1329+        ApiError extends unknown ? Ctx["_error"] : ApiError
1330+      >
1331     >,
1332   ): CreateActionWithPayload<
1333     & Omit<Ctx, "payload" | "json">
1334     & Payload<P>
1335-    & FetchJson<ApiSuccess, ApiError>,
1336-    P
1337+    & FetchJson<
1338+      ApiSuccess,
1339+      ApiError extends unknown ? Ctx["_error"] : ApiError
1340+    >,
1341+    P,
1342+    ApiSuccess
1343   >;
1344 
1345   /**
1346@@ -1067,21 +1638,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1347   put<P extends never, ApiSuccess, ApiError = unknown>(
1348     name: ApiName,
1349     req: { supervisor?: Supervisor },
1350-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1351-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1352+    fn: MiddlewareApiCo<
1353+      & Omit<Ctx, "json">
1354+      & FetchJson<
1355+        ApiSuccess,
1356+        ApiError extends unknown ? Ctx["_error"] : ApiError
1357+      >
1358+    >,
1359+  ): CreateAction<
1360+    & Omit<Ctx, "json">
1361+    & FetchJson<
1362+      ApiSuccess,
1363+      ApiError extends unknown ? Ctx["_error"] : ApiError
1364+    >,
1365+    ApiSuccess
1366+  >;
1367   put<P, ApiSuccess, ApiError = unknown>(
1368     name: ApiName,
1369     req: { supervisor?: Supervisor },
1370     fn: MiddlewareApiCo<
1371       & Omit<Ctx, "payload" | "json">
1372       & Payload<P>
1373-      & FetchJson<ApiSuccess, ApiError>
1374+      & FetchJson<
1375+        ApiSuccess,
1376+        ApiError extends unknown ? Ctx["_error"] : ApiError
1377+      >
1378     >,
1379   ): CreateActionWithPayload<
1380     & Omit<Ctx, "payload" | "json">
1381     & Payload<P>
1382-    & FetchJson<ApiSuccess, ApiError>,
1383-    P
1384+    & FetchJson<
1385+      ApiSuccess,
1386+      ApiError extends unknown ? Ctx["_error"] : ApiError
1387+    >,
1388+    P,
1389+    ApiSuccess
1390   >;
1391 
1392   /**
1393@@ -1093,14 +1684,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1394   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1395   patch<P extends never, ApiSuccess, ApiError = unknown>(
1396     name: ApiName,
1397-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1398+  ): CreateAction<
1399+    & Omit<Ctx, "json">
1400+    & FetchJson<
1401+      ApiSuccess,
1402+      ApiError extends unknown ? Ctx["_error"] : ApiError
1403+    >,
1404+    ApiSuccess
1405+  >;
1406   patch<P, ApiSuccess, ApiError = unknown>(
1407     name: ApiName,
1408   ): CreateActionWithPayload<
1409     & Omit<Ctx, "payload" | "json">
1410     & Payload<P>
1411-    & FetchJson<ApiSuccess, ApiError>,
1412-    P
1413+    & FetchJson<
1414+      ApiSuccess,
1415+      ApiError extends unknown ? Ctx["_error"] : ApiError
1416+    >,
1417+    P,
1418+    ApiSuccess
1419   >;
1420 
1421   /**
1422@@ -1118,15 +1720,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1423   patch<P extends never, ApiSuccess, ApiError = unknown>(
1424     name: ApiName,
1425     req: { supervisor?: Supervisor },
1426-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1427+  ): CreateAction<
1428+    & Omit<Ctx, "json">
1429+    & FetchJson<
1430+      ApiSuccess,
1431+      ApiError extends unknown ? Ctx["_error"] : ApiError
1432+    >,
1433+    ApiSuccess
1434+  >;
1435   patch<P, ApiSuccess, ApiError = unknown>(
1436     name: ApiName,
1437     req: { supervisor?: Supervisor },
1438   ): CreateActionWithPayload<
1439     & Omit<Ctx, "payload" | "json">
1440     & Payload<P>
1441-    & FetchJson<ApiSuccess, ApiError>,
1442-    P
1443+    & FetchJson<
1444+      ApiSuccess,
1445+      ApiError extends unknown ? Ctx["_error"] : ApiError
1446+    >,
1447+    P,
1448+    ApiSuccess
1449   >;
1450 
1451   /**
1452@@ -1147,20 +1760,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1453   ): CreateActionWithPayload<Gtx, P>;
1454   patch<P extends never, ApiSuccess, ApiError = unknown>(
1455     name: ApiName,
1456-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1457-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1458+    fn: MiddlewareApiCo<
1459+      & Omit<Ctx, "json">
1460+      & FetchJson<
1461+        ApiSuccess,
1462+        ApiError extends unknown ? Ctx["_error"] : ApiError
1463+      >
1464+    >,
1465+  ): CreateAction<
1466+    & Omit<Ctx, "json">
1467+    & FetchJson<
1468+      ApiSuccess,
1469+      ApiError extends unknown ? Ctx["_error"] : ApiError
1470+    >,
1471+    ApiSuccess
1472+  >;
1473   patch<P, ApiSuccess, ApiError = unknown>(
1474     name: ApiName,
1475     fn: MiddlewareApiCo<
1476       & Omit<Ctx, "payload" | "json">
1477       & Payload<P>
1478-      & FetchJson<ApiSuccess, ApiError>
1479+      & FetchJson<
1480+        ApiSuccess,
1481+        ApiError extends unknown ? Ctx["_error"] : ApiError
1482+      >
1483     >,
1484   ): CreateActionWithPayload<
1485     & Omit<Ctx, "payload" | "json">
1486     & Payload<P>
1487-    & FetchJson<ApiSuccess, ApiError>,
1488-    P
1489+    & FetchJson<
1490+      ApiSuccess,
1491+      ApiError extends unknown ? Ctx["_error"] : ApiError
1492+    >,
1493+    P,
1494+    ApiSuccess
1495   >;
1496 
1497   /**
1498@@ -1189,21 +1822,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1499   patch<P extends never, ApiSuccess, ApiError = unknown>(
1500     name: ApiName,
1501     req: { supervisor?: Supervisor },
1502-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1503-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1504+    fn: MiddlewareApiCo<
1505+      & Omit<Ctx, "json">
1506+      & FetchJson<
1507+        ApiSuccess,
1508+        ApiError extends unknown ? Ctx["_error"] : ApiError
1509+      >
1510+    >,
1511+  ): CreateAction<
1512+    & Omit<Ctx, "json">
1513+    & FetchJson<
1514+      ApiSuccess,
1515+      ApiError extends unknown ? Ctx["_error"] : ApiError
1516+    >,
1517+    ApiSuccess
1518+  >;
1519   patch<P, ApiSuccess, ApiError = unknown>(
1520     name: ApiName,
1521     req: { supervisor?: Supervisor },
1522     fn: MiddlewareApiCo<
1523       & Omit<Ctx, "payload" | "json">
1524       & Payload<P>
1525-      & FetchJson<ApiSuccess, ApiError>
1526+      & FetchJson<
1527+        ApiSuccess,
1528+        ApiError extends unknown ? Ctx["_error"] : ApiError
1529+      >
1530     >,
1531   ): CreateActionWithPayload<
1532     & Omit<Ctx, "payload" | "json">
1533     & Payload<P>
1534-    & FetchJson<ApiSuccess, ApiError>,
1535-    P
1536+    & FetchJson<
1537+      ApiSuccess,
1538+      ApiError extends unknown ? Ctx["_error"] : ApiError
1539+    >,
1540+    P,
1541+    ApiSuccess
1542   >;
1543 
1544   /**
1545@@ -1215,14 +1868,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1546   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1547   delete<P extends never, ApiSuccess, ApiError = unknown>(
1548     name: ApiName,
1549-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1550+  ): CreateAction<
1551+    & Omit<Ctx, "json">
1552+    & FetchJson<
1553+      ApiSuccess,
1554+      ApiError extends unknown ? Ctx["_error"] : ApiError
1555+    >,
1556+    ApiSuccess
1557+  >;
1558   delete<P, ApiSuccess, ApiError = unknown>(
1559     name: ApiName,
1560   ): CreateActionWithPayload<
1561     & Omit<Ctx, "payload" | "json">
1562     & Payload<P>
1563-    & FetchJson<ApiSuccess, ApiError>,
1564-    P
1565+    & FetchJson<
1566+      ApiSuccess,
1567+      ApiError extends unknown ? Ctx["_error"] : ApiError
1568+    >,
1569+    P,
1570+    ApiSuccess
1571   >;
1572 
1573   /**
1574@@ -1240,15 +1904,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1575   delete<P extends never, ApiSuccess, ApiError = unknown>(
1576     name: ApiName,
1577     req: { supervisor?: Supervisor },
1578-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1579+  ): CreateAction<
1580+    & Omit<Ctx, "json">
1581+    & FetchJson<
1582+      ApiSuccess,
1583+      ApiError extends unknown ? Ctx["_error"] : ApiError
1584+    >,
1585+    ApiSuccess
1586+  >;
1587   delete<P, ApiSuccess, ApiError = unknown>(
1588     name: ApiName,
1589     req: { supervisor?: Supervisor },
1590   ): CreateActionWithPayload<
1591     & Omit<Ctx, "payload" | "json">
1592     & Payload<P>
1593-    & FetchJson<ApiSuccess, ApiError>,
1594-    P
1595+    & FetchJson<
1596+      ApiSuccess,
1597+      ApiError extends unknown ? Ctx["_error"] : ApiError
1598+    >,
1599+    P,
1600+    ApiSuccess
1601   >;
1602 
1603   /**
1604@@ -1269,20 +1944,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1605   ): CreateActionWithPayload<Gtx, P>;
1606   delete<P extends never, ApiSuccess, ApiError = unknown>(
1607     name: ApiName,
1608-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1609-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1610+    fn: MiddlewareApiCo<
1611+      & Omit<Ctx, "json">
1612+      & FetchJson<
1613+        ApiSuccess,
1614+        ApiError extends unknown ? Ctx["_error"] : ApiError
1615+      >
1616+    >,
1617+  ): CreateAction<
1618+    & Omit<Ctx, "json">
1619+    & FetchJson<
1620+      ApiSuccess,
1621+      ApiError extends unknown ? Ctx["_error"] : ApiError
1622+    >,
1623+    ApiSuccess
1624+  >;
1625   delete<P, ApiSuccess, ApiError = unknown>(
1626     name: ApiName,
1627     fn: MiddlewareApiCo<
1628       & Omit<Ctx, "payload" | "json">
1629       & Payload<P>
1630-      & FetchJson<ApiSuccess, ApiError>
1631+      & FetchJson<
1632+        ApiSuccess,
1633+        ApiError extends unknown ? Ctx["_error"] : ApiError
1634+      >
1635     >,
1636   ): CreateActionWithPayload<
1637     & Omit<Ctx, "payload" | "json">
1638     & Payload<P>
1639-    & FetchJson<ApiSuccess, ApiError>,
1640-    P
1641+    & FetchJson<
1642+      ApiSuccess,
1643+      ApiError extends unknown ? Ctx["_error"] : ApiError
1644+    >,
1645+    P,
1646+    ApiSuccess
1647   >;
1648 
1649   /**
1650@@ -1311,21 +2006,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1651   delete<P extends never, ApiSuccess, ApiError = unknown>(
1652     name: ApiName,
1653     req: { supervisor?: Supervisor },
1654-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1655-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1656+    fn: MiddlewareApiCo<
1657+      & Omit<Ctx, "json">
1658+      & FetchJson<
1659+        ApiSuccess,
1660+        ApiError extends unknown ? Ctx["_error"] : ApiError
1661+      >
1662+    >,
1663+  ): CreateAction<
1664+    & Omit<Ctx, "json">
1665+    & FetchJson<
1666+      ApiSuccess,
1667+      ApiError extends unknown ? Ctx["_error"] : ApiError
1668+    >,
1669+    ApiSuccess
1670+  >;
1671   delete<P, ApiSuccess, ApiError = unknown>(
1672     name: ApiName,
1673     req: { supervisor?: Supervisor },
1674     fn: MiddlewareApiCo<
1675       & Omit<Ctx, "payload" | "json">
1676       & Payload<P>
1677-      & FetchJson<ApiSuccess, ApiError>
1678+      & FetchJson<
1679+        ApiSuccess,
1680+        ApiError extends unknown ? Ctx["_error"] : ApiError
1681+      >
1682     >,
1683   ): CreateActionWithPayload<
1684     & Omit<Ctx, "payload" | "json">
1685     & Payload<P>
1686-    & FetchJson<ApiSuccess, ApiError>,
1687-    P
1688+    & FetchJson<
1689+      ApiSuccess,
1690+      ApiError extends unknown ? Ctx["_error"] : ApiError
1691+    >,
1692+    P,
1693+    ApiSuccess
1694   >;
1695 
1696   /**
1697@@ -1337,14 +2052,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1698   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1699   options<P extends never, ApiSuccess, ApiError = unknown>(
1700     name: ApiName,
1701-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1702+  ): CreateAction<
1703+    & Omit<Ctx, "json">
1704+    & FetchJson<
1705+      ApiSuccess,
1706+      ApiError extends unknown ? Ctx["_error"] : ApiError
1707+    >,
1708+    ApiSuccess
1709+  >;
1710   options<P, ApiSuccess, ApiError = unknown>(
1711     name: ApiName,
1712   ): CreateActionWithPayload<
1713     & Omit<Ctx, "payload" | "json">
1714     & Payload<P>
1715-    & FetchJson<ApiSuccess, ApiError>,
1716-    P
1717+    & FetchJson<
1718+      ApiSuccess,
1719+      ApiError extends unknown ? Ctx["_error"] : ApiError
1720+    >,
1721+    P,
1722+    ApiSuccess
1723   >;
1724 
1725   /**
1726@@ -1362,15 +2088,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1727   options<P extends never, ApiSuccess, ApiError = unknown>(
1728     name: ApiName,
1729     req: { supervisor?: Supervisor },
1730-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1731+  ): CreateAction<
1732+    & Omit<Ctx, "json">
1733+    & FetchJson<
1734+      ApiSuccess,
1735+      ApiError extends unknown ? Ctx["_error"] : ApiError
1736+    >,
1737+    ApiSuccess
1738+  >;
1739   options<P, ApiSuccess, ApiError = unknown>(
1740     name: ApiName,
1741     req: { supervisor?: Supervisor },
1742   ): CreateActionWithPayload<
1743     & Omit<Ctx, "payload" | "json">
1744     & Payload<P>
1745-    & FetchJson<ApiSuccess, ApiError>,
1746-    P
1747+    & FetchJson<
1748+      ApiSuccess,
1749+      ApiError extends unknown ? Ctx["_error"] : ApiError
1750+    >,
1751+    P,
1752+    ApiSuccess
1753   >;
1754 
1755   /**
1756@@ -1391,20 +2128,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1757   ): CreateActionWithPayload<Gtx, P>;
1758   options<P extends never, ApiSuccess, ApiError = unknown>(
1759     name: ApiName,
1760-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1761-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1762+    fn: MiddlewareApiCo<
1763+      & Omit<Ctx, "json">
1764+      & FetchJson<
1765+        ApiSuccess,
1766+        ApiError extends unknown ? Ctx["_error"] : ApiError
1767+      >
1768+    >,
1769+  ): CreateAction<
1770+    & Omit<Ctx, "json">
1771+    & FetchJson<
1772+      ApiSuccess,
1773+      ApiError extends unknown ? Ctx["_error"] : ApiError
1774+    >,
1775+    ApiSuccess
1776+  >;
1777   options<P, ApiSuccess, ApiError = unknown>(
1778     name: ApiName,
1779     fn: MiddlewareApiCo<
1780       & Omit<Ctx, "payload" | "json">
1781       & Payload<P>
1782-      & FetchJson<ApiSuccess, ApiError>
1783+      & FetchJson<
1784+        ApiSuccess,
1785+        ApiError extends unknown ? Ctx["_error"] : ApiError
1786+      >
1787     >,
1788   ): CreateActionWithPayload<
1789     & Omit<Ctx, "payload" | "json">
1790     & Payload<P>
1791-    & FetchJson<ApiSuccess, ApiError>,
1792-    P
1793+    & FetchJson<
1794+      ApiSuccess,
1795+      ApiError extends unknown ? Ctx["_error"] : ApiError
1796+    >,
1797+    P,
1798+    ApiSuccess
1799   >;
1800 
1801   /**
1802@@ -1433,21 +2190,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1803   options<P extends never, ApiSuccess, ApiError = unknown>(
1804     name: ApiName,
1805     req: { supervisor?: Supervisor },
1806-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1807-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1808+    fn: MiddlewareApiCo<
1809+      & Omit<Ctx, "json">
1810+      & FetchJson<
1811+        ApiSuccess,
1812+        ApiError extends unknown ? Ctx["_error"] : ApiError
1813+      >
1814+    >,
1815+  ): CreateAction<
1816+    & Omit<Ctx, "json">
1817+    & FetchJson<
1818+      ApiSuccess,
1819+      ApiError extends unknown ? Ctx["_error"] : ApiError
1820+    >,
1821+    ApiSuccess
1822+  >;
1823   options<P, ApiSuccess, ApiError = unknown>(
1824     name: ApiName,
1825     req: { supervisor?: Supervisor },
1826     fn: MiddlewareApiCo<
1827       & Omit<Ctx, "payload" | "json">
1828       & Payload<P>
1829-      & FetchJson<ApiSuccess, ApiError>
1830+      & FetchJson<
1831+        ApiSuccess,
1832+        ApiError extends unknown ? Ctx["_error"] : ApiError
1833+      >
1834     >,
1835   ): CreateActionWithPayload<
1836     & Omit<Ctx, "payload" | "json">
1837     & Payload<P>
1838-    & FetchJson<ApiSuccess, ApiError>,
1839-    P
1840+    & FetchJson<
1841+      ApiSuccess,
1842+      ApiError extends unknown ? Ctx["_error"] : ApiError
1843+    >,
1844+    P,
1845+    ApiSuccess
1846   >;
1847 
1848   /**
1849@@ -1459,14 +2236,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1850   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
1851   head<P extends never, ApiSuccess, ApiError = unknown>(
1852     name: ApiName,
1853-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1854+  ): CreateAction<
1855+    & Omit<Ctx, "json">
1856+    & FetchJson<
1857+      ApiSuccess,
1858+      ApiError extends unknown ? Ctx["_error"] : ApiError
1859+    >,
1860+    ApiSuccess
1861+  >;
1862   head<P, ApiSuccess, ApiError = unknown>(
1863     name: ApiName,
1864   ): CreateActionWithPayload<
1865     & Omit<Ctx, "payload" | "json">
1866     & Payload<P>
1867-    & FetchJson<ApiSuccess, ApiError>,
1868-    P
1869+    & FetchJson<
1870+      ApiSuccess,
1871+      ApiError extends unknown ? Ctx["_error"] : ApiError
1872+    >,
1873+    P,
1874+    ApiSuccess
1875   >;
1876 
1877   /**
1878@@ -1484,15 +2272,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1879   head<P extends never, ApiSuccess, ApiError = unknown>(
1880     name: ApiName,
1881     req: { supervisor?: Supervisor },
1882-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1883+  ): CreateAction<
1884+    & Omit<Ctx, "json">
1885+    & FetchJson<
1886+      ApiSuccess,
1887+      ApiError extends unknown ? Ctx["_error"] : ApiError
1888+    >,
1889+    ApiSuccess
1890+  >;
1891   head<P, ApiSuccess, ApiError = unknown>(
1892     name: ApiName,
1893     req: { supervisor?: Supervisor },
1894   ): CreateActionWithPayload<
1895     & Omit<Ctx, "payload" | "json">
1896     & Payload<P>
1897-    & FetchJson<ApiSuccess, ApiError>,
1898-    P
1899+    & FetchJson<
1900+      ApiSuccess,
1901+      ApiError extends unknown ? Ctx["_error"] : ApiError
1902+    >,
1903+    P,
1904+    ApiSuccess
1905   >;
1906 
1907   /**
1908@@ -1513,20 +2312,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1909   ): CreateActionWithPayload<Gtx, P>;
1910   head<P extends never, ApiSuccess, ApiError = unknown>(
1911     name: ApiName,
1912-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1913-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1914+    fn: MiddlewareApiCo<
1915+      & Omit<Ctx, "json">
1916+      & FetchJson<
1917+        ApiSuccess,
1918+        ApiError extends unknown ? Ctx["_error"] : ApiError
1919+      >
1920+    >,
1921+  ): CreateAction<
1922+    & Omit<Ctx, "json">
1923+    & FetchJson<
1924+      ApiSuccess,
1925+      ApiError extends unknown ? Ctx["_error"] : ApiError
1926+    >,
1927+    ApiSuccess
1928+  >;
1929   head<P, ApiSuccess, ApiError = unknown>(
1930     name: ApiName,
1931     fn: MiddlewareApiCo<
1932       & Omit<Ctx, "payload" | "json">
1933       & Payload<P>
1934-      & FetchJson<ApiSuccess, ApiError>
1935+      & FetchJson<
1936+        ApiSuccess,
1937+        ApiError extends unknown ? Ctx["_error"] : ApiError
1938+      >
1939     >,
1940   ): CreateActionWithPayload<
1941     & Omit<Ctx, "payload" | "json">
1942     & Payload<P>
1943-    & FetchJson<ApiSuccess, ApiError>,
1944-    P
1945+    & FetchJson<
1946+      ApiSuccess,
1947+      ApiError extends unknown ? Ctx["_error"] : ApiError
1948+    >,
1949+    P,
1950+    ApiSuccess
1951   >;
1952 
1953   /**
1954@@ -1555,21 +2374,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
1955   head<P extends never, ApiSuccess, ApiError = unknown>(
1956     name: ApiName,
1957     req: { supervisor?: Supervisor },
1958-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
1959-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
1960+    fn: MiddlewareApiCo<
1961+      & Omit<Ctx, "json">
1962+      & FetchJson<
1963+        ApiSuccess,
1964+        ApiError extends unknown ? Ctx["_error"] : ApiError
1965+      >
1966+    >,
1967+  ): CreateAction<
1968+    & Omit<Ctx, "json">
1969+    & FetchJson<
1970+      ApiSuccess,
1971+      ApiError extends unknown ? Ctx["_error"] : ApiError
1972+    >,
1973+    ApiSuccess
1974+  >;
1975   head<P, ApiSuccess, ApiError = unknown>(
1976     name: ApiName,
1977     req: { supervisor?: Supervisor },
1978     fn: MiddlewareApiCo<
1979       & Omit<Ctx, "payload" | "json">
1980       & Payload<P>
1981-      & FetchJson<ApiSuccess, ApiError>
1982+      & FetchJson<
1983+        ApiSuccess,
1984+        ApiError extends unknown ? Ctx["_error"] : ApiError
1985+      >
1986     >,
1987   ): CreateActionWithPayload<
1988     & Omit<Ctx, "payload" | "json">
1989     & Payload<P>
1990-    & FetchJson<ApiSuccess, ApiError>,
1991-    P
1992+    & FetchJson<
1993+      ApiSuccess,
1994+      ApiError extends unknown ? Ctx["_error"] : ApiError
1995+    >,
1996+    P,
1997+    ApiSuccess
1998   >;
1999 
2000   /**
2001@@ -1581,14 +2420,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2002   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
2003   connect<P extends never, ApiSuccess, ApiError = unknown>(
2004     name: ApiName,
2005-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2006+  ): CreateAction<
2007+    & Omit<Ctx, "json">
2008+    & FetchJson<
2009+      ApiSuccess,
2010+      ApiError extends unknown ? Ctx["_error"] : ApiError
2011+    >,
2012+    ApiSuccess
2013+  >;
2014   connect<P, ApiSuccess, ApiError = unknown>(
2015     name: ApiName,
2016   ): CreateActionWithPayload<
2017     & Omit<Ctx, "payload" | "json">
2018     & Payload<P>
2019-    & FetchJson<ApiSuccess, ApiError>,
2020-    P
2021+    & FetchJson<
2022+      ApiSuccess,
2023+      ApiError extends unknown ? Ctx["_error"] : ApiError
2024+    >,
2025+    P,
2026+    ApiSuccess
2027   >;
2028 
2029   /**
2030@@ -1606,15 +2456,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2031   connect<P extends never, ApiSuccess, ApiError = unknown>(
2032     name: ApiName,
2033     req: { supervisor?: Supervisor },
2034-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2035+  ): CreateAction<
2036+    & Omit<Ctx, "json">
2037+    & FetchJson<
2038+      ApiSuccess,
2039+      ApiError extends unknown ? Ctx["_error"] : ApiError
2040+    >,
2041+    ApiSuccess
2042+  >;
2043   connect<P, ApiSuccess, ApiError = unknown>(
2044     name: ApiName,
2045     req: { supervisor?: Supervisor },
2046   ): CreateActionWithPayload<
2047     & Omit<Ctx, "payload" | "json">
2048     & Payload<P>
2049-    & FetchJson<ApiSuccess, ApiError>,
2050-    P
2051+    & FetchJson<
2052+      ApiSuccess,
2053+      ApiError extends unknown ? Ctx["_error"] : ApiError
2054+    >,
2055+    P,
2056+    ApiSuccess
2057   >;
2058 
2059   /**
2060@@ -1635,20 +2496,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2061   ): CreateActionWithPayload<Gtx, P>;
2062   connect<P extends never, ApiSuccess, ApiError = unknown>(
2063     name: ApiName,
2064-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
2065-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2066+    fn: MiddlewareApiCo<
2067+      & Omit<Ctx, "json">
2068+      & FetchJson<
2069+        ApiSuccess,
2070+        ApiError extends unknown ? Ctx["_error"] : ApiError
2071+      >
2072+    >,
2073+  ): CreateAction<
2074+    & Omit<Ctx, "json">
2075+    & FetchJson<
2076+      ApiSuccess,
2077+      ApiError extends unknown ? Ctx["_error"] : ApiError
2078+    >,
2079+    ApiSuccess
2080+  >;
2081   connect<P, ApiSuccess, ApiError = unknown>(
2082     name: ApiName,
2083     fn: MiddlewareApiCo<
2084       & Omit<Ctx, "payload" | "json">
2085       & Payload<P>
2086-      & FetchJson<ApiSuccess, ApiError>
2087+      & FetchJson<
2088+        ApiSuccess,
2089+        ApiError extends unknown ? Ctx["_error"] : ApiError
2090+      >
2091     >,
2092   ): CreateActionWithPayload<
2093     & Omit<Ctx, "payload" | "json">
2094     & Payload<P>
2095-    & FetchJson<ApiSuccess, ApiError>,
2096-    P
2097+    & FetchJson<
2098+      ApiSuccess,
2099+      ApiError extends unknown ? Ctx["_error"] : ApiError
2100+    >,
2101+    P,
2102+    ApiSuccess
2103   >;
2104 
2105   /**
2106@@ -1677,21 +2558,41 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2107   connect<P extends never, ApiSuccess, ApiError = unknown>(
2108     name: ApiName,
2109     req: { supervisor?: Supervisor },
2110-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
2111-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2112+    fn: MiddlewareApiCo<
2113+      & Omit<Ctx, "json">
2114+      & FetchJson<
2115+        ApiSuccess,
2116+        ApiError extends unknown ? Ctx["_error"] : ApiError
2117+      >
2118+    >,
2119+  ): CreateAction<
2120+    & Omit<Ctx, "json">
2121+    & FetchJson<
2122+      ApiSuccess,
2123+      ApiError extends unknown ? Ctx["_error"] : ApiError
2124+    >,
2125+    ApiSuccess
2126+  >;
2127   connect<P, ApiSuccess, ApiError = unknown>(
2128     name: ApiName,
2129     req: { supervisor?: Supervisor },
2130     fn: MiddlewareApiCo<
2131       & Omit<Ctx, "payload" | "json">
2132       & Payload<P>
2133-      & FetchJson<ApiSuccess, ApiError>
2134+      & FetchJson<
2135+        ApiSuccess,
2136+        ApiError extends unknown ? Ctx["_error"] : ApiError
2137+      >
2138     >,
2139   ): CreateActionWithPayload<
2140     & Omit<Ctx, "payload" | "json">
2141     & Payload<P>
2142-    & FetchJson<ApiSuccess, ApiError>,
2143-    P
2144+    & FetchJson<
2145+      ApiSuccess,
2146+      ApiError extends unknown ? Ctx["_error"] : ApiError
2147+    >,
2148+    P,
2149+    ApiSuccess
2150   >;
2151 
2152   /**
2153@@ -1703,14 +2604,25 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2154   ): CreateActionWithPayload<Omit<Ctx, "payload"> & Payload<P>, P>;
2155   trace<P extends never, ApiSuccess, ApiError = unknown>(
2156     name: ApiName,
2157-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2158+  ): CreateAction<
2159+    & Omit<Ctx, "json">
2160+    & FetchJson<
2161+      ApiSuccess,
2162+      ApiError extends unknown ? Ctx["_error"] : ApiError
2163+    >,
2164+    ApiSuccess
2165+  >;
2166   trace<P, ApiSuccess, ApiError = unknown>(
2167     name: ApiName,
2168   ): CreateActionWithPayload<
2169     & Omit<Ctx, "payload" | "json">
2170     & Payload<P>
2171-    & FetchJson<ApiSuccess, ApiError>,
2172-    P
2173+    & FetchJson<
2174+      ApiSuccess,
2175+      ApiError extends unknown ? Ctx["_error"] : ApiError
2176+    >,
2177+    P,
2178+    ApiSuccess
2179   >;
2180 
2181   /**
2182@@ -1728,15 +2640,26 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2183   trace<P extends never, ApiSuccess, ApiError = unknown>(
2184     name: ApiName,
2185     req: { supervisor?: Supervisor },
2186-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2187+  ): CreateAction<
2188+    & Omit<Ctx, "json">
2189+    & FetchJson<
2190+      ApiSuccess,
2191+      ApiError extends unknown ? Ctx["_error"] : ApiError
2192+    >,
2193+    ApiSuccess
2194+  >;
2195   trace<P, ApiSuccess, ApiError = unknown>(
2196     name: ApiName,
2197     req: { supervisor?: Supervisor },
2198   ): CreateActionWithPayload<
2199     & Omit<Ctx, "payload" | "json">
2200     & Payload<P>
2201-    & FetchJson<ApiSuccess, ApiError>,
2202-    P
2203+    & FetchJson<
2204+      ApiSuccess,
2205+      ApiError extends unknown ? Ctx["_error"] : ApiError
2206+    >,
2207+    P,
2208+    ApiSuccess
2209   >;
2210 
2211   /**
2212@@ -1757,20 +2680,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2213   ): CreateActionWithPayload<Gtx, P>;
2214   trace<P extends never, ApiSuccess, ApiError = unknown>(
2215     name: ApiName,
2216-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
2217-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2218+    fn: MiddlewareApiCo<
2219+      & Omit<Ctx, "json">
2220+      & FetchJson<
2221+        ApiSuccess,
2222+        ApiError extends unknown ? Ctx["_error"] : ApiError
2223+      >
2224+    >,
2225+  ): CreateAction<
2226+    & Omit<Ctx, "json">
2227+    & FetchJson<
2228+      ApiSuccess,
2229+      ApiError extends unknown ? Ctx["_error"] : ApiError
2230+    >,
2231+    ApiSuccess
2232+  >;
2233   trace<P, ApiSuccess, ApiError = unknown>(
2234     name: ApiName,
2235     fn: MiddlewareApiCo<
2236       & Omit<Ctx, "payload" | "json">
2237       & Payload<P>
2238-      & FetchJson<ApiSuccess, ApiError>
2239+      & FetchJson<
2240+        ApiSuccess,
2241+        ApiError extends unknown ? Ctx["_error"] : ApiError
2242+      >
2243     >,
2244   ): CreateActionWithPayload<
2245     & Omit<Ctx, "payload" | "json">
2246     & Payload<P>
2247-    & FetchJson<ApiSuccess, ApiError>,
2248-    P
2249+    & FetchJson<
2250+      ApiSuccess,
2251+      ApiError extends unknown ? Ctx["_error"] : ApiError
2252+    >,
2253+    P,
2254+    ApiSuccess
2255   >;
2256 
2257   /**
2258@@ -1799,20 +2742,40 @@ export interface QueryApi<Ctx extends ApiCtx = ApiCtx> extends ThunksApi<Ctx> {
2259   trace<P extends never, ApiSuccess, ApiError = unknown>(
2260     name: ApiName,
2261     req: { supervisor?: Supervisor },
2262-    fn: MiddlewareApiCo<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>,
2263-  ): CreateAction<Omit<Ctx, "json"> & FetchJson<ApiSuccess, ApiError>>;
2264+    fn: MiddlewareApiCo<
2265+      & Omit<Ctx, "json">
2266+      & FetchJson<
2267+        ApiSuccess,
2268+        ApiError extends unknown ? Ctx["_error"] : ApiError
2269+      >
2270+    >,
2271+  ): CreateAction<
2272+    & Omit<Ctx, "json">
2273+    & FetchJson<
2274+      ApiSuccess,
2275+      ApiError extends unknown ? Ctx["_error"] : ApiError
2276+    >,
2277+    ApiSuccess
2278+  >;
2279   trace<P, ApiSuccess, ApiError = unknown>(
2280     name: ApiName,
2281     req: { supervisor?: Supervisor },
2282     fn: MiddlewareApiCo<
2283       & Omit<Ctx, "payload" | "json">
2284       & Payload<P>
2285-      & FetchJson<ApiSuccess, ApiError>
2286+      & FetchJson<
2287+        ApiSuccess,
2288+        ApiError extends unknown ? Ctx["_error"] : ApiError
2289+      >
2290     >,
2291   ): CreateActionWithPayload<
2292     & Omit<Ctx, "payload" | "json">
2293     & Payload<P>
2294-    & FetchJson<ApiSuccess, ApiError>,
2295-    P
2296+    & FetchJson<
2297+      ApiSuccess,
2298+      ApiError extends unknown ? Ctx["_error"] : ApiError
2299+    >,
2300+    P,
2301+    ApiSuccess
2302   >;
2303 }
M query/api.test.ts
+46, -1
 1@@ -15,6 +15,7 @@ import { createApi } from "./api.ts";
 2 import { createKey } from "./create-key.ts";
 3 import type { ApiCtx } from "./types.ts";
 4 import { call } from "../deps.ts";
 5+import { useCache } from "./react.ts";
 6 
 7 interface User {
 8   id: string;
 9@@ -339,7 +340,7 @@ it(tests, "createApi - two identical endpoints", async () => {
10   expect(actual).toEqual(["/health", "/health"]);
11 });
12 
13-interface TestCtx<P = any, S = any, E = any> extends ApiCtx<P, S, E> {
14+interface TestCtx<P = any, S = any> extends ApiCtx<P, S, { message: string }> {
15   something: boolean;
16 }
17 
18@@ -480,3 +481,47 @@ it(tests, "should bubble up error", () => {
19     "Cannot read properties of undefined (reading 'thisKeyDoesNotExist')",
20   );
21 });
22+
23+// this is strictly for testing types
24+it(
25+  tests,
26+  "useCache - derive api success from endpoint",
27+  () => {
28+    const api = createApi<TestCtx>();
29+    api.use(api.routes());
30+    api.use(function* (ctx, next) {
31+      yield* next();
32+      const data = { result: "wow" };
33+      ctx.json = { ok: true, data, value: data };
34+    });
35+
36+    const acc: string[] = [];
37+    const action1 = api.get<never, { result: string }>(
38+      "/users",
39+      { supervisor: takeEvery },
40+      function* (ctx, next) {
41+        ctx.something = false;
42+
43+        yield* next();
44+
45+        if (ctx.json.ok) {
46+          acc.push(ctx.json.value.result);
47+        } else {
48+          // EXPECT { message: string }
49+          ctx.json.error;
50+        }
51+      },
52+    );
53+
54+    const store = configureStore({ initialState: { users: {} } });
55+    store.run(api.bootup);
56+
57+    function _App() {
58+      const act = action1();
59+      act.payload._result;
60+      const users = useCache(act);
61+      // EXPECT { result: string } | undefined
62+      users.data;
63+    }
64+  },
65+);
M query/react.ts
+3, -3
 1@@ -158,9 +158,9 @@ export function useQuery<P = any, A extends ThunkAction = ThunkAction<P>>(
 2  * }
 3  * ```
 4  */
 5-export function useCache<D = any, A extends ThunkAction = ThunkAction>(
 6-  action: A,
 7-): UseCacheResult<D, A> {
 8+export function useCache<P = any, ApiSuccess = any>(
 9+  action: ThunkAction<P, ApiSuccess>,
10+): UseCacheResult<typeof action.payload._result, ThunkAction<P, ApiSuccess>> {
11   const id = action.payload.key;
12   const data: any = useSelector((s: any) => selectDataById(s, { id }));
13   const query = useQuery(action);
M query/thunk.ts
+2, -0
1@@ -224,6 +224,8 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
2       }
3     };
4     actionFn.toString = () => name;
5+    actionFn._success = {};
6+    actionFn._error = {};
7     actionMap[name] = actionFn;
8 
9     return actionFn;
M query/types.ts
+25, -13
 1@@ -67,6 +67,8 @@ export interface ApiCtx<Payload = any, ApiSuccess = any, ApiError = any>
 2   stub: boolean;
 3   // previously cached data
 4   cacheData: any;
 5+  _success: ApiSuccess;
 6+  _error: ApiError;
 7 }
 8 
 9 export interface PerfCtx<P = unknown> extends ThunkCtx<P> {
10@@ -99,38 +101,48 @@ export interface ActionWithPayload<P> extends Action {
11   payload: P;
12 }
13 
14-export interface CreateActionPayload<P = any> {
15+export interface CreateActionPayload<P = any, ApiSuccess = any> {
16   name: string;
17   key: string;
18   options: P;
19+  _result: ApiSuccess;
20 }
21 
22-export type ThunkAction<P = any> = ActionWithPayload<CreateActionPayload<P>>;
23-
24-export type CreateActionFn = () => ActionWithPayload<
25-  CreateActionPayload<Record<string | number | symbol, never>>
26+export type CreateActionFn<ApiSuccess = any> = () => ActionWithPayload<
27+  CreateActionPayload<Record<string | number | symbol, never>, ApiSuccess>
28 >;
29 
30-export interface CreateAction<Ctx extends ThunkCtx = ThunkCtx>
31-  extends CreateActionFn {
32+export interface CreateAction<
33+  Ctx extends ThunkCtx = ThunkCtx,
34+  ApiSuccess = any,
35+> extends CreateActionFn<ApiSuccess> {
36   run: (
37     p?: ActionWithPayload<
38-      CreateActionPayload<Record<string | number | symbol, never>>
39+      CreateActionPayload<Record<string | number | symbol, never>, ApiSuccess>
40     >,
41   ) => Operation<Ctx>;
42   use: (mdw: Middleware<Ctx>) => void;
43 }
44 
45-export type CreateActionFnWithPayload<P = any> = (
46+export type CreateActionFnWithPayload<P = any, ApiSuccess = any> = (
47   p: P,
48-) => ActionWithPayload<CreateActionPayload<P>>;
49+) => ActionWithPayload<CreateActionPayload<P, ApiSuccess>>;
50 
51-export interface CreateActionWithPayload<Ctx extends ThunkCtx, P>
52-  extends CreateActionFnWithPayload<P> {
53-  run: (a: ActionWithPayload<CreateActionPayload<P>> | P) => Operation<Ctx>;
54+export interface CreateActionWithPayload<
55+  Ctx extends ThunkCtx,
56+  P,
57+  ApiSuccess = any,
58+> extends CreateActionFnWithPayload<P, ApiSuccess> {
59+  run: (
60+    a: ActionWithPayload<CreateActionPayload<P, ApiSuccess>> | P,
61+  ) => Operation<Ctx>;
62   use: (mdw: Middleware<Ctx>) => void;
63 }
64 
65+export type ThunkAction<P = any, ApiSuccess = any> = ActionWithPayload<
66+  CreateActionPayload<P, ApiSuccess>
67+>;
68+
69 export type Supervisor<T = unknown> = (
70   pattern: string,
71   op: (action: Action) => Operation<T>,