Skip to content

Comments

chore(js-ts): Replace any types with proper TypeScript interfaces in RootState#320

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1771438151-add-reducer-types
Open

chore(js-ts): Replace any types with proper TypeScript interfaces in RootState#320
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1771438151-add-reducer-types

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Feb 18, 2026

chore(js-ts): Replace any types with proper TypeScript interfaces in RootState

Summary

Replaces all 18 any-typed reducer state entries in the RootState interface (app/reducers/index.ts) with proper TypeScript interfaces derived from each reducer's initialState and action handlers. Additionally fixes all downstream type errors surfaced by the concrete types across ~24 files.

Reducers typed: legalNotices, collectibles, privacy, bookmarks, browser, modals, settings, alert, transaction, wizard, notification, swaps, infuraAvailability, networkOnboarded, experimentalSettings, signatureRequest, rpcEvents, accounts

Approach:

  • For TS reducers that already export state types (rpcEventsiEventGroup, accountsiAccountEvent), those types are imported directly.
  • For signatureRequest, a flexible inline interface is defined with string types for reason/result_type (rather than importing the strict SecurityAlertResponse enum type from BlockaidBanner) to avoid cascading enum mismatches in test files and consuming components.
  • For JS reducers, new interfaces were defined in index.ts based on the reducer's initialState shape and all action-handler mutations. JS reducers are cast as Reducer<T> in baseReducers since TypeScript infers narrower types from their initialState than the declared interfaces allow.
  • All corresponding // TODO: Replace "any" and // eslint-disable-next-line @typescript-eslint/no-explicit-any comments were removed.
  • app/util/test/initial-root-state.ts now provides concrete initial state objects instead of undefined for all typed reducers.
  • Test files updated with DeepPartial<RootState> annotations and corrected mock data to satisfy the new concrete types.

Updates since last revision

  • Snapshot update: Updated app/util/sentry/__snapshots__/utils.test.ts.snap and the corresponding mock state in utils.test.ts to reflect the new concrete initial root state. Three diffs: bookmarks changed from {} to [] (matching the reducer's array initialState), removed stale receiveAsset/receiveModalVisible from modals (not in reducer initialState), and removed nested notification.notificationsSettings (not in reducer initialState). All unit tests now pass (10/10 shards green).

  • Previous fixes (still included):

    • BrowserTab.id type conflict: Changed app/components/UI/Tokens/types.ts BrowserTab.id from string to number to match the browser reducer (which uses Date.now()).
    • injectHomePageScripts parameter: Updated BrowserTab.tsx and RPCMethodMiddleware.ts to accept Bookmark[] instead of string[].
    • Test mock corrections: Fixed ~15 test files with incorrect mock data (e.g., transaction.id: 123'123', selectedAsset: ''{}, activeTab: ''null, approvedHosts: []{}).
    • TransactionBlockaidBanner.tsx: Added as SecurityAlertResponse cast when passing securityAlertResponse to BlockaidBanner.
    • initial-root-state.ts: Populated all 18 reducer states with concrete initial values matching their reducer initialState.

This is a types-only change — no runtime behavior is affected.

Review & Testing Checklist for Human

  • BrowserTab.id: number change: Verify that all code creating or passing BrowserTab objects uses numeric IDs. The browser reducer uses Date.now(), but check if any external code (e.g., deep links, navigation params) passes string IDs that would now be silently mistyped.
  • TransactionBlockaidBanner.tsx unsafe cast: The securityAlertResponse as SecurityAlertResponse cast assumes the object from Record<string, unknown> satisfies the SecurityAlertResponse interface. Verify the selector always returns a properly-shaped object, or consider adding runtime validation.
  • Test mock data changes: Several tests had mock data corrected (e.g., origin removed from transaction state, id changed from number to string). Verify these weren't intentionally testing edge cases that now won't be caught.
  • initial-root-state.ts hardcoded values: The concrete initial states (e.g., signMessageModalVisible: true, searchEngine: 'DuckDuckGo', lockTime: -1) must match the actual reducer initialState values. If reducers change their defaults, this file must be updated or tests will use stale values.
  • Snapshot changes: The updated snapshot reflects bookmarks: [] (not {}), removed receiveAsset/receiveModalVisible from modals, and removed nested notification.notificationsSettings. Verify these align with the actual reducer initialState values.

Suggested test plan:

  1. Run full typecheck (yarn lint:tsc) — should pass clean ✅ (verified locally; CI cancelled this check due to infrastructure issues)
  2. Run unit tests (yarn test) — all 10 shards passed ✅
  3. Manually test browser tab creation, Blockaid banner display, and swaps functionality to verify runtime behavior is unchanged

Notes

  • All 18 new interfaces are defined directly in app/reducers/index.ts rather than co-located with their reducers. This keeps the change minimal and avoids touching JS reducer files, but a future refactor could move types into per-reducer types.ts files (like user/types.ts).
  • The StateFromReducer utility type still uses any in its conditional — this is intentional and separate from the RootState typing effort.
  • CI status: Four checks failed but are unrelated to this PR: CLABot (auth), check-pr-labels (repo config), check-diff (Ruby setup on runner), audit:ci (pre-existing dependency vulnerabilities). Three checks were cancelled due to CI infrastructure cascading from the failed checks: lint:tsc, lint, test:depcheck. All code-related checks that ran passed: unit tests (10/10 shards), build, security scans, E2E gate checks.

Link to Devin run: https://app.devin.ai/sessions/16d6fa47fdd54f22b2fe8f4c40ad7413
Requested by: @shannonhittson-eng

…RootState

Co-Authored-By: Shannon Hittson <shannon.hittson@cognition.ai>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits February 18, 2026 18:41
Co-Authored-By: Shannon Hittson <shannon.hittson@cognition.ai>
Co-Authored-By: Shannon Hittson <shannon.hittson@cognition.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants