chore(js-ts): Replace AnyAction with typed RootAction union#597
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
chore(js-ts): Replace AnyAction with typed RootAction union#597devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- 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>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Devin Review
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the TODO at
app/store/index.tsto improve type safety by replacingAnyActionwith real Action types.Changes
New file
app/store/actionTypes.ts: Defines aRootActionunion type that aggregates all known typed action types across the codebase:UserAction,SecurityAction,SdkAction,OnboardingActionTypes,NavigationAction,RpcEventAction,AccountAction,LegalNoticesAction,FiatOrderActionAction<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:persistReducernow usesRootActioninstead ofAnyAction. Removed the TODO comment.app/core/redux/types.ts:ReduxStoretype now usesRootActioninstead ofAnyAction. Removed the TODO comment.app/reducers/index.ts:rootReduceris explicitly typed asReducer<RootState, RootAction>(cast from the internalcombineReducerswhich still usesanydue to narrow per-reducer action types). Updated comment to explain the approach.app/components/hooks/useThunkDispatch.ts:ThunkActionanduseThunkDispatchnow useRootActioninstead ofAnyAction.app/core/DeeplinkManager/DeeplinkManager.ts:dispatchproperty and constructor param now useRootActionandRootStateinstead ofAnyAction/any. Removed two TODO comments.After this change, zero references to
AnyActionremain in theapp/directory.Review & Testing Checklist for Human
RootActionunion inapp/store/actionTypes.tscovers all typed action modules — check no typed action union was missedAction<string>fallback doesn't mask type errors for already-typed dispatch call sitestsc --noEmitto verify no type regressionsNotes
combineReducerscall still usesanyinternally because individual typed reducers (e.g.userReduceracceptingUserAction) have narrow action types that are not assignable to the widerRootActionunion under strict function parameter contravariance. The cast toReducer<RootState, RootAction>at the export boundary is safe because all reducers handle unknown action types via theirdefaultcase.RootActionand theAction<string>fallback can be removed.Link to Devin session: https://app.devin.ai/sessions/5b5e0a3b9818479cbfa874c5d5da1361
Requested by: @dr-phil