Skip to content

chore(js-ts): Replace AnyAction with typed RootAction union#597

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1777411461-improve-persist-reducer-type-safety
Open

chore(js-ts): Replace AnyAction with typed RootAction union#597
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1777411461-improve-persist-reducer-type-safety

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 28, 2026

Summary

Addresses the TODO at app/store/index.ts to improve type safety by replacing AnyAction with real Action types.

Changes

  • New file app/store/actionTypes.ts: Defines a RootAction union type that aggregates all known typed action types across the codebase:

    • UserAction, SecurityAction, SdkAction, OnboardingActionTypes, NavigationAction, RpcEventAction, AccountAction, LegalNoticesAction, FiatOrderAction
    • Plus Action<string> as a fallback for the 11 action modules still written in JS (alert, bookmarks, browser, collectibles, infuraAvailability, modals, notification, privacy, settings, transaction, wizard). This fallback can be removed as those files are migrated to TypeScript.
  • app/store/index.ts: persistReducer now uses RootAction instead of AnyAction. Removed the TODO comment.

  • app/core/redux/types.ts: ReduxStore type now uses RootAction instead of AnyAction. Removed the TODO comment.

  • app/reducers/index.ts: rootReducer is explicitly typed as Reducer<RootState, RootAction> (cast from the internal combineReducers which still uses any due to narrow per-reducer action types). Updated comment to explain the approach.

  • app/components/hooks/useThunkDispatch.ts: ThunkAction and useThunkDispatch now use RootAction instead of AnyAction.

  • app/core/DeeplinkManager/DeeplinkManager.ts: dispatch property and constructor param now use RootAction and RootState instead of AnyAction/any. Removed two TODO comments.

After this change, zero references to AnyAction remain in the app/ directory.

Review & Testing Checklist for Human

  • Verify RootAction union in app/store/actionTypes.ts covers all typed action modules — check no typed action union was missed
  • Confirm the Action<string> fallback doesn't mask type errors for already-typed dispatch call sites
  • Run tsc --noEmit to verify no type regressions

Notes

  • The combineReducers call still uses any internally because individual typed reducers (e.g. userReducer accepting UserAction) have narrow action types that are not assignable to the wider RootAction union under strict function parameter contravariance. The cast to Reducer<RootState, RootAction> at the export boundary is safe because all reducers handle unknown action types via their default case.
  • As the remaining 11 JS action files are migrated to TypeScript (tracked in the JS→TS migration playbooks), their action types should be added to RootAction and the Action<string> fallback can be removed.

Link to Devin session: https://app.devin.ai/sessions/5b5e0a3b9818479cbfa874c5d5da1361
Requested by: @dr-phil


Open in Devin Review

- Create app/store/actionTypes.ts with RootAction union type covering
  all typed action modules (UserAction, SecurityAction, SdkAction,
  OnboardingActionTypes, NavigationAction, RpcEventAction, AccountAction,
  LegalNoticesAction, FiatOrderAction) plus Action<string> fallback for
  untyped JS reducers
- Update persistReducer generic from AnyAction to RootAction
- Update ReduxStore type from AnyAction to RootAction
- Update combineReducers result to Reducer<RootState, RootAction>
- Update useThunkDispatch hook from AnyAction to RootAction
- Update DeeplinkManager dispatch typing from AnyAction to RootAction
- Remove all AnyAction references from app/ directory

Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
@devin-ai-integration
Copy link
Copy Markdown
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

@staging-devin-ai-integration
Copy link
Copy Markdown

Devin Review

Status Commit
⚪ Not started

Open in Devin Review (Staging)

💡 Connect your GitHub account to enable automatic code reviews.

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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.

1 participant