@@ -40,6 +40,7 @@ import type { WritableDraft } from 'immer/dist/internal.js';
40
40
import { cloneDeep } from 'lodash' ;
41
41
42
42
import type { MultichainNetworkControllerNetworkDidChangeEvent } from './types' ;
43
+ import type { AccountsControllerStrictState } from './typing' ;
43
44
import type { HdSnapKeyringAccount } from './utils' ;
44
45
import {
45
46
getEvmDerivationPathForIndex ,
@@ -604,7 +605,8 @@ export class AccountsController extends BaseController<
604
605
}
605
606
606
607
this . #update( ( state ) => {
607
- state . internalAccounts . accounts = internalAccounts ;
608
+ ( state as AccountsControllerStrictState ) . internalAccounts . accounts =
609
+ internalAccounts ;
608
610
} ) ;
609
611
}
610
612
@@ -615,9 +617,11 @@ export class AccountsController extends BaseController<
615
617
*/
616
618
loadBackup ( backup : AccountsControllerState ) : void {
617
619
if ( backup . internalAccounts ) {
618
- this . update ( ( currentState ) => {
619
- currentState . internalAccounts = backup . internalAccounts ;
620
- } ) ;
620
+ this . update (
621
+ ( currentState : WritableDraft < AccountsControllerStrictState > ) => {
622
+ currentState . internalAccounts = backup . internalAccounts ;
623
+ } ,
624
+ ) ;
621
625
}
622
626
}
623
627
@@ -906,13 +910,20 @@ export class AccountsController extends BaseController<
906
910
*
907
911
* @param callback - Callback for updating state, passed a draft state object.
908
912
*/
909
- #update( callback : ( state : WritableDraft < AccountsControllerState > ) => void ) {
913
+ #update(
914
+ callback : ( state : WritableDraft < AccountsControllerStrictState > ) => void ,
915
+ ) {
910
916
// The currently selected account might get deleted during the update, so keep track
911
917
// of it before doing any change.
912
918
const previouslySelectedAccount =
913
919
this . state . internalAccounts . selectedAccount ;
914
920
915
- this . update ( ( state ) => {
921
+ this . update ( ( draft : WritableDraft < AccountsControllerState > ) => {
922
+ // By-passing recursive-type issue. We have other type-assertion that checks that both
923
+ // types are compatible.
924
+ const state = draft as WritableDraft < AccountsControllerStrictState > ;
925
+
926
+ // We're casting this type to avoid having this same error in every `#update` calls.
916
927
callback ( state ) ;
917
928
918
929
// If the account no longer exists (or none is selected), we need to re-select another one.
0 commit comments