@@ -1405,7 +1405,8 @@ function updateSplitTransactions({
14051405 } ;
14061406
14071407 // Collect optimistic child transactions to add to the search snapshot (forward split only)
1408- const optimisticChildSnapshotEntries : Record < string , OnyxTypes . Transaction > = { } ;
1408+ const optimisticChildSnapshotEntries : SearchResultDataType = { } ;
1409+ const optimisticChildSnapshotKeys : Array < `${typeof ONYXKEYS . COLLECTION . TRANSACTION } ${string } `> = [ ] ;
14091410
14101411 for ( const [ index , splitExpense ] of splitExpenses . entries ( ) ) {
14111412 const existingTransactionID = isReverseSplitOperation ? originalTransactionID : splitExpense . transactionID ;
@@ -1919,7 +1920,7 @@ function updateSplitTransactions({
19191920 // Collect the optimistic child transaction for snapshot update (forward split only)
19201921 if ( ! isReverseSplitOperation && optimisticTransactionFromGetMoneyRequest ) {
19211922 const childTransactionID = optimisticTransactionFromGetMoneyRequest . transactionID ;
1922- const transactionKey = `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ childTransactionID } ` ;
1923+ const transactionKey : `${ typeof ONYXKEYS . COLLECTION . TRANSACTION } ${ string } ` = `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ childTransactionID } ` ;
19231924 // Use the transaction value from optimisticData if available (it may have merchant fixes applied),
19241925 // otherwise fall back to the raw optimistic transaction
19251926 const transactionUpdate = moneyRequestInformationOnyxData . optimisticData ?. find ( ( update ) => update . key === transactionKey ) ;
@@ -1928,6 +1929,7 @@ function updateSplitTransactions({
19281929 ? ( transactionUpdate . value as OnyxTypes . Transaction )
19291930 : optimisticTransactionFromGetMoneyRequest ;
19301931 optimisticChildSnapshotEntries [ transactionKey ] = snapshotTransaction ;
1932+ optimisticChildSnapshotKeys . push ( transactionKey ) ;
19311933 }
19321934
19331935 onyxData . optimisticData ?. push ( ...( moneyRequestInformationOnyxData . optimisticData ?? [ ] ) , ...( updateMoneyRequestParamsOnyxData . optimisticData ?? [ ] ) , ...optimisticDataComments ) ;
@@ -2140,20 +2142,19 @@ function updateSplitTransactions({
21402142 }
21412143
21422144 // Build the snapshot data update: remove original transaction and add child transactions
2143- const optimisticSnapshotData : Record < string , OnyxTypes . Transaction | null > = {
2145+ const optimisticSnapshotData : SearchResultDataType = {
21442146 [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ] : null ,
21452147 ...optimisticChildSnapshotEntries ,
21462148 } ;
21472149
21482150 // On failure, restore the original transaction and remove the child transactions
2149- const failureSnapshotData : Record < string , OnyxTypes . Transaction | null > = {
2150- [ ` ${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ] : originalTransaction ?? null ,
2151- } ;
2152- for ( const childKey of Object . keys ( optimisticChildSnapshotEntries ) ) {
2151+ // Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
2152+ const failureSnapshotData : NullishDeep < SearchResultDataType > = { } ;
2153+ failureSnapshotData [ ` ${ ONYXKEYS . COLLECTION . TRANSACTION } ${ originalTransactionID } ` ] = originalTransaction ?? null ;
2154+ for ( const childKey of optimisticChildSnapshotKeys ) {
21532155 failureSnapshotData [ childKey ] = null ;
21542156 }
21552157
2156- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
21572158 onyxData . optimisticData ?. push ( {
21582159 onyxMethod : Onyx . METHOD . MERGE ,
21592160 key : `${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ searchContext ?. currentSearchHash } ` ,
@@ -2162,7 +2163,6 @@ function updateSplitTransactions({
21622163 } ,
21632164 } ) ;
21642165
2165- // @ts -expect-error - will be solved in https://github.com/Expensify/App/issues/73830
21662166 onyxData . failureData ?. push ( {
21672167 onyxMethod : Onyx . METHOD . MERGE ,
21682168 key : `${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ searchContext ?. currentSearchHash } ` ,
0 commit comments