Difficulty: Intermediate
Type: refactor
Background
The codebase is ~95% TypeScript per the repo's language breakdown, and every other hook/module lives in .ts/.tsx. lib/hooks/usePagination.js is the one exception: it's plain JavaScript with a hand-maintained, separate lib/hooks/usePagination.d.ts declaration file. This hook is actively used by app/admin/members/page.tsx to paginate the filtered member list.
Problem
Maintaining a .js implementation alongside a manually written .d.ts is error-prone — the two can silently drift out of sync (e.g., a new return field added to the hook but not to the type declaration, or vice versa), and it breaks the project's "everything is TypeScript" convention, making the hook harder to refactor safely with full type inference.
Expected Outcome
lib/hooks/usePagination.js and lib/hooks/usePagination.d.ts are replaced by a single lib/hooks/usePagination.ts file with inline types, behaviorally identical to today, and all existing call sites and tests continue to work unmodified (aside from import path, which stays the same).
Suggested Implementation
- Create
lib/hooks/usePagination.ts, porting the logic from usePagination.js and merging in the type signatures currently declared in usePagination.d.ts (generic item type, pageSize: number, return shape with currentPage, totalPages, paginatedItems, nextPage, prevPage, setPage, setCurrentPage).
- Make the hook generic (
usePagination<T>(items: T[], pageSize: number)) so consumers get typed paginatedItems.
- Delete
usePagination.js and usePagination.d.ts.
- Update the import in
app/admin/members/page.tsx if the file extension/module resolution requires it (it shouldn't, since imports omit extensions).
- Add/port a unit test file (
test/use-pagination.test.ts) covering boundary conditions: empty array, pageSize of 0 or negative (should not throw), setPage clamping, nextPage/prevPage at boundaries.
Acceptance Criteria
Likely Affected Files/Directories
lib/hooks/usePagination.js (removed)
lib/hooks/usePagination.d.ts (removed)
lib/hooks/usePagination.ts (new)
app/admin/members/page.tsx
test/ (new test file)
Difficulty: Intermediate
Type: refactor
Background
The codebase is ~95% TypeScript per the repo's language breakdown, and every other hook/module lives in
.ts/.tsx.lib/hooks/usePagination.jsis the one exception: it's plain JavaScript with a hand-maintained, separatelib/hooks/usePagination.d.tsdeclaration file. This hook is actively used byapp/admin/members/page.tsxto paginate the filtered member list.Problem
Maintaining a
.jsimplementation alongside a manually written.d.tsis error-prone — the two can silently drift out of sync (e.g., a new return field added to the hook but not to the type declaration, or vice versa), and it breaks the project's "everything is TypeScript" convention, making the hook harder to refactor safely with full type inference.Expected Outcome
lib/hooks/usePagination.jsandlib/hooks/usePagination.d.tsare replaced by a singlelib/hooks/usePagination.tsfile with inline types, behaviorally identical to today, and all existing call sites and tests continue to work unmodified (aside from import path, which stays the same).Suggested Implementation
lib/hooks/usePagination.ts, porting the logic fromusePagination.jsand merging in the type signatures currently declared inusePagination.d.ts(generic item type,pageSize: number, return shape withcurrentPage,totalPages,paginatedItems,nextPage,prevPage,setPage,setCurrentPage).usePagination<T>(items: T[], pageSize: number)) so consumers get typedpaginatedItems.usePagination.jsandusePagination.d.ts.app/admin/members/page.tsxif the file extension/module resolution requires it (it shouldn't, since imports omit extensions).test/use-pagination.test.ts) covering boundary conditions: empty array,pageSizeof 0 or negative (should not throw),setPageclamping,nextPage/prevPageat boundaries.Acceptance Criteria
lib/hooks/usePagination.jsandlib/hooks/usePagination.d.tsno longer exist.lib/hooks/usePagination.tsexports a generically typedusePagination<T>.app/admin/members/page.tsxcompiles and behaves identically (page navigation, filtered counts).npm run typecheck,npm run lint, andnpm testall pass.Likely Affected Files/Directories
lib/hooks/usePagination.js(removed)lib/hooks/usePagination.d.ts(removed)lib/hooks/usePagination.ts(new)app/admin/members/page.tsxtest/(new test file)