Skip to content

Commit 8e4c9ec

Browse files
docs: Improve ExampleDataService types (#10001)
## Explanation `ExampleDataService` is not type checked, so we had missed some type inference issues. This PR fixes them. ## References N/A ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only example service typing and pagination guards; no production runtime behavior change. > > **Overview** > Updates **`ExampleDataService.getActivity`** so infinite-query types infer correctly once the example is type-checked. > > **`fetchInfiniteQuery`** no longer passes an explicit **`GetActivityResponse`** generic; **`initialPageParam`** is **`null as PageParam`** so **`TPageParam`** lines up with **`getPreviousPageParam`** / **`getNextPageParam`**. Pagination branches use **`'after' in pageParam`** and **`'before' in pageParam`** instead of optional chaining on **`pageParam`**, with eslint disables where the project restricts that syntax. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f9f85dc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 707eecf commit 8e4c9ec

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

packages/base-data-service/tests/ExampleDataService.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,21 @@ export class ExampleDataService extends BaseDataService<
127127
address: string,
128128
page?: PageParam,
129129
): Promise<GetActivityResponse> {
130-
return this.fetchInfiniteQuery<GetActivityResponse>(
130+
return this.fetchInfiniteQuery(
131131
{
132132
queryKey: [`${this.name}:getActivity`, address],
133-
initialPageParam: null,
133+
initialPageParam: null as PageParam,
134134
queryFn: async ({ pageParam }) => {
135135
const caipAddress = `eip155:0:${address.toLowerCase()}`;
136136
const url = new URL(
137137
`${this.#accountsBaseUrl}/v4/multiaccount/transactions?limit=3&accountAddresses=${caipAddress}`,
138138
);
139139

140-
if (pageParam?.after) {
140+
// eslint-disable-next-line no-restricted-syntax
141+
if (pageParam && 'after' in pageParam) {
141142
url.searchParams.set('after', pageParam.after);
142-
} else if (pageParam?.before) {
143+
// eslint-disable-next-line no-restricted-syntax
144+
} else if (pageParam && 'before' in pageParam) {
143145
url.searchParams.set('before', pageParam.before);
144146
}
145147

0 commit comments

Comments
 (0)