FAQ
Paginated query loop errors with TS7022
When you page through a list= module, you may end up carrying the continuation cursor as a single variable that both goes into the request and comes back out of the response:
This only triggers when your client's return type is chosen by the caller (a generic get<T> / post<T> returning Promise<T>). Clients that cast the result — as in (await api.get({ … })) as ApiQueryResponse — never run into it.
Cause. res's type is inferred from the call, and the call's argument is the object literal just above. That literal embeds the shorthand property cmcontinue (1), so typing the argument first needs the type of cmcontinue — but cmcontinue is assigned back from res at (2). The dependency runs straight back into the binding being declared:
TypeScript cannot resolve the cycle, so under noImplicitAny it gives up and types res as any. The TS7006 you then see on m in the .map((m) => …) line is just fallout.
Fix — any one of these breaks the cycle.
-
Annotate the response, so its type no longer has to be inferred through the argument:
-
Spread a single, independently typed
continueobject in place of the cursor variable, so the request body references nothing derived fromresinside its own initializer: -
Cast the awaited result instead of passing a type argument: