chore(js-ts): Replace AnyAction with RootAction for improved type safety#593
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
chore(js-ts): Replace AnyAction with RootAction for improved type safety#593devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Define a RootAction union type that combines all typed Redux action modules (UserAction, NavigationAction, OnboardingActionTypes, SecurityAction, SdkAction, FiatOrdersAction, iAccountActions, iEventAction) with Action<string> as a fallback for untyped JS actions and RTK slice actions. Replace AnyAction usage in: - persistReducer (app/store/index.ts) - ReduxStore type (app/core/redux/types.ts) - useThunkDispatch hook (app/components/hooks/useThunkDispatch.ts) - DeeplinkManager (app/core/DeeplinkManager/DeeplinkManager.ts) This prevents arbitrary property access on action objects without proper type narrowing, improving type safety across the Redux store. As more action modules are migrated to TypeScript, they should be added to the RootAction union. Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
Devin Review
|
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:
|
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 in
app/store/index.tsto improve type safety by replacingAnyActionwith real Action types.What changed:
RootActionunion type inapp/reducers/index.tsthat combines all currently typed Redux action modules (UserAction,NavigationAction,OnboardingActionTypes,SecurityAction,SdkAction,FiatOrdersAction,iAccountActions,iEventAction) withAction<string>as a fallback for untyped JS actions and RTK slice actions.AnyActionwithRootActionin:persistReducercall (app/store/index.ts)ReduxStoretype (app/core/redux/types.ts)useThunkDispatchhook (app/components/hooks/useThunkDispatch.ts)DeeplinkManagerdispatch type (app/core/DeeplinkManager/DeeplinkManager.ts)Why this matters:
AnyActionis{ type: string; [extraProps: string]: any }, which allows accessing any property on an action object without type checking.RootActionprevents arbitrary property access without proper type narrowing, requiring consumers to narrow viaswitch (action.type)to get typed access to action-specific fields.As more action modules are migrated from JS to TS (per the ongoing migration playbooks), they should be added to the
RootActionunion for progressively stronger type safety.Review & Testing Checklist for Human
tsc --noEmitpasses with no new type errors introduced by theRootActiontypeNotes
combineReducers<RootState, any>inapp/reducers/index.ts(line 182) is left asanyintentionally — changing it would require all individual TS reducers to acceptRootAction, which is a larger refactor tracked by a separate TODO.app/core/redux/types.tsforReduxStore.any-typed dispatch and removed// TODOcomments inDeeplinkManager.ts.Link to Devin session: https://app.devin.ai/sessions/9da3f26404ca4d04a2f7eed7899137eb
Requested by: @dr-phil