Skip to content

Commit 383e6d0

Browse files
authored
Merge pull request Expensify#82786 from software-mansion-labs/@OlGierd03/remove-all-ts-expect-errors-comments-second
Resolve `@ts-expect-error` comments related to OnyxUpdate changes - second batch
2 parents 986ed0f + c925ac1 commit 383e6d0

19 files changed

Lines changed: 269 additions & 220 deletions

src/libs/Navigation/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ type WorkspaceSplitNavigatorParamList = {
26702670
};
26712671
[SCREENS.WORKSPACE.RECEIPT_PARTNERS_CHANGE_BILLING_ACCOUNT]: {
26722672
policyID: string;
2673-
integration: string;
2673+
integration: ValueOf<typeof CONST.POLICY.RECEIPT_PARTNERS.NAME>;
26742674
};
26752675

26762676
[SCREENS.WORKSPACE.RECEIPT_PARTNERS_INVITE_EDIT]: {

src/libs/SearchQueryUtils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {addDays, endOfMonth, format, parse, startOfMonth, startOfYear, subMonths} from 'date-fns';
22
import cloneDeep from 'lodash/cloneDeep';
33
import Onyx from 'react-native-onyx';
4-
import type {OnyxCollection, OnyxUpdate} from 'react-native-onyx';
4+
import type {NullishDeep, OnyxCollection, OnyxUpdate} from 'react-native-onyx';
55
import type {ValueOf} from 'type-fest';
66
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
77
import type {
@@ -33,7 +33,7 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form';
3333
import FILTER_KEYS, {ALLOWED_TYPE_FILTERS, AMOUNT_FILTER_KEYS, DATE_FILTER_KEYS} from '@src/types/form/SearchAdvancedFiltersForm';
3434
import type {ExpenseTypeValue, ExpenseTypeValues, HasFilterValue, HasFilterValues, IsFilterValue, IsFilterValues, SearchAdvancedFiltersKey} from '@src/types/form/SearchAdvancedFiltersForm';
3535
import type * as OnyxTypes from '@src/types/onyx';
36-
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
36+
import type {SearchDataTypes, SearchResultDataType} from '@src/types/onyx/SearchResults';
3737
import {getCardFeedsForDisplay} from './CardFeedUtils';
3838
import {getCardDescription} from './CardUtils';
3939
import {convertToBackendAmount, convertToFrontendAmountAsInteger} from './CurrencyUtils';
@@ -1995,7 +1995,7 @@ function buildFilterQueryWithSortDefaults(
19951995
/**
19961996
* Builds an optimistic Snapshot update to ensure offline data for Tasks and Chat messages appears in Search.
19971997
*/
1998-
function buildOptimisticSnapshotData(type: SearchDataTypes, data: Record<string, unknown>): OnyxUpdate<typeof ONYXKEYS.COLLECTION.SNAPSHOT> | undefined {
1998+
function buildOptimisticSnapshotData(type: SearchDataTypes, data: NullishDeep<SearchResultDataType>): OnyxUpdate<typeof ONYXKEYS.COLLECTION.SNAPSHOT> | undefined {
19991999
const searchQuery = buildCannedSearchQuery({type});
20002000
const searchQueryJSON = buildSearchQueryJSON(searchQuery);
20012001
if (!searchQueryJSON) {
@@ -2005,7 +2005,6 @@ function buildOptimisticSnapshotData(type: SearchDataTypes, data: Record<string,
20052005
onyxMethod: Onyx.METHOD.MERGE,
20062006
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${searchQueryJSON.hash}`,
20072007
value: {
2008-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
20092008
data,
20102009
},
20112010
};

src/libs/actions/ClearReportActionErrors.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {OnyxCollection} from 'react-native-onyx';
1+
import type {NullishDeep, OnyxCollection} from 'react-native-onyx';
22
import Onyx from 'react-native-onyx';
33
import {getLinkedTransactionID, getReportAction, getReportActionMessage, isCreatedTaskReportAction, isRejectedAction} from '@libs/ReportActionsUtils';
44
import {getOriginalReportID} from '@libs/ReportUtils';
@@ -7,6 +7,7 @@ import CONST from '@src/CONST';
77
import ONYXKEYS from '@src/ONYXKEYS';
88
import type * as OnyxTypes from '@src/types/onyx';
99
import type ReportAction from '@src/types/onyx/ReportAction';
10+
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
1011
import {deleteReport} from './Report';
1112

1213
type IgnoreDirection = 'parent' | 'child';
@@ -69,9 +70,9 @@ function clearReportActionErrors(reportAction: ReportAction, originalReportID: s
6970
}
7071

7172
// Clear the chat snapshot entries for the failed optimistic action(s) so they disappear from Reports > Chats.
72-
const snapshotDataToClear: Record<string, unknown> = {
73-
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`]: actionsToDelete,
74-
};
73+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
74+
const snapshotDataToClear: NullishDeep<SearchResultDataType> = {};
75+
snapshotDataToClear[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`] = actionsToDelete;
7576
if (taskReportID && isCreatedTaskReportAction(reportAction)) {
7677
// If this is a failed optimistic task-create action, also remove the task report snapshot data so it disappears from Reports > Task when the user dismiss the error.
7778
snapshotDataToClear[`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`] = null;

src/libs/actions/IOU/BulkEdit.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {createTransactionThreadReport} from '@userActions/Report';
2828
import CONST from '@src/CONST';
2929
import ONYXKEYS from '@src/ONYXKEYS';
3030
import type * as OnyxTypes from '@src/types/onyx';
31+
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
3132
import type {TransactionChanges} from '@src/types/onyx/Transaction';
3233
import {getAllTransactionViolations, getCurrentUserEmail, getUpdatedMoneyRequestReportData, getUserAccountID} from '.';
3334

@@ -345,42 +346,40 @@ function updateMultipleMoneyRequests({
345346
// new values immediately (the snapshot is the exclusive data source for search
346347
// result rendering and is not automatically updated by the TRANSACTION write above).
347348
if (hash) {
349+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
350+
const optimisticSnapshotData: NullishDeep<SearchResultDataType> = {};
351+
optimisticSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = {...updatedTransaction, pendingFields};
352+
if (optimisticViolationsData && optimisticViolationsData.onyxMethod === Onyx.METHOD.SET) {
353+
optimisticSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] = optimisticViolationsData.value;
354+
}
348355
snapshotOptimisticData.push({
349356
onyxMethod: Onyx.METHOD.MERGE,
350357
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}` as const,
351358
value: {
352-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
353-
data: {
354-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {
355-
...updatedTransaction,
356-
pendingFields,
357-
},
358-
...(optimisticViolationsData && {[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]: optimisticViolationsData.value}),
359-
},
359+
data: optimisticSnapshotData,
360360
},
361361
});
362+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
363+
const successSnapshotData: NullishDeep<SearchResultDataType> = {};
364+
successSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = {pendingFields: clearedPendingFields};
362365
snapshotSuccessData.push({
363366
onyxMethod: Onyx.METHOD.MERGE,
364367
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}` as const,
365368
value: {
366-
data: {
367-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
368-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {pendingFields: clearedPendingFields},
369-
},
369+
data: successSnapshotData,
370370
},
371371
});
372+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
373+
const failureSnapshotData: NullishDeep<SearchResultDataType> = {};
374+
failureSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = {...transaction, pendingFields: clearedPendingFields};
375+
if (currentTransactionViolations) {
376+
failureSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] = currentTransactionViolations;
377+
}
372378
snapshotFailureData.push({
373379
onyxMethod: Onyx.METHOD.MERGE,
374380
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}` as const,
375381
value: {
376-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
377-
data: {
378-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {
379-
...transaction,
380-
pendingFields: clearedPendingFields,
381-
},
382-
...(currentTransactionViolations && {[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]: currentTransactionViolations}),
383-
},
382+
data: failureSnapshotData,
384383
},
385384
});
386385
}

src/libs/actions/IOU/DeleteMoneyRequest.ts

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,23 @@ function cleanUpMoneyRequest(
387387
value: updatedReportAction,
388388
});
389389
}
390-
onyxUpdates.push(
391-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
392-
{
393-
onyxMethod: Onyx.METHOD.MERGE,
394-
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
395-
value: updatedIOUReport,
396-
},
397-
{
398-
onyxMethod: Onyx.METHOD.MERGE,
399-
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
400-
value: getOutstandingChildRequest(updatedIOUReport),
401-
},
402-
);
390+
391+
if (updatedIOUReport) {
392+
if (iouReport?.reportID) {
393+
onyxUpdates.push({
394+
onyxMethod: Onyx.METHOD.MERGE,
395+
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
396+
value: updatedIOUReport,
397+
});
398+
}
399+
if (chatReport?.reportID) {
400+
onyxUpdates.push({
401+
onyxMethod: Onyx.METHOD.MERGE,
402+
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
403+
value: getOutstandingChildRequest(updatedIOUReport),
404+
});
405+
}
406+
}
403407

404408
if (!shouldDeleteIOUReport && updatedReportPreviewAction.childMoneyRequestCount === 0) {
405409
onyxUpdates.push({
@@ -695,24 +699,28 @@ function deleteMoneyRequest({
695699

696700
removeTransactionFromDuplicateTransactionViolation({optimisticData, failureData}, transactionID, transactions, violations);
697701

698-
optimisticData.push(
699-
{
700-
onyxMethod: Onyx.METHOD.MERGE,
701-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`,
702-
value: updatedReportAction,
703-
},
704-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
705-
{
706-
onyxMethod: Onyx.METHOD.MERGE,
707-
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
708-
value: updatedIOUReport,
709-
},
710-
{
711-
onyxMethod: Onyx.METHOD.MERGE,
712-
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
713-
value: getOutstandingChildRequest(updatedIOUReport),
714-
},
715-
);
702+
optimisticData.push({
703+
onyxMethod: Onyx.METHOD.MERGE,
704+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`,
705+
value: updatedReportAction,
706+
});
707+
708+
if (updatedIOUReport) {
709+
if (iouReport?.reportID) {
710+
optimisticData.push({
711+
onyxMethod: Onyx.METHOD.MERGE,
712+
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
713+
value: updatedIOUReport,
714+
});
715+
}
716+
if (chatReport?.reportID) {
717+
optimisticData.push({
718+
onyxMethod: Onyx.METHOD.MERGE,
719+
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
720+
value: getOutstandingChildRequest(updatedIOUReport),
721+
});
722+
}
723+
}
716724

717725
if (reportPreviewAction?.reportActionID) {
718726
optimisticData.push({
@@ -844,10 +852,11 @@ function deleteMoneyRequest({
844852
};
845853
}
846854
}
847-
failureData.push(
848-
{
855+
856+
if (iouReport?.reportID) {
857+
failureData.push({
849858
onyxMethod: Onyx.METHOD.MERGE,
850-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`,
859+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
851860
value: {
852861
...originalReportActionsUpdate,
853862
[reportAction.reportActionID]: {
@@ -856,20 +865,22 @@ function deleteMoneyRequest({
856865
errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericDeleteFailureMessage', errorKey),
857866
},
858867
},
859-
},
860-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
861-
shouldDeleteIOUReport
862-
? {
863-
onyxMethod: Onyx.METHOD.SET,
864-
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
865-
value: iouReport,
866-
}
867-
: {
868-
onyxMethod: Onyx.METHOD.MERGE,
869-
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
870-
value: iouReport,
871-
},
872-
);
868+
});
869+
870+
failureData.push(
871+
shouldDeleteIOUReport
872+
? {
873+
onyxMethod: Onyx.METHOD.SET,
874+
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
875+
value: iouReport,
876+
}
877+
: {
878+
onyxMethod: Onyx.METHOD.MERGE,
879+
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`,
880+
value: iouReport,
881+
},
882+
);
883+
}
873884

874885
if (reportPreviewAction?.reportActionID) {
875886
failureData.push({

src/libs/actions/IOU/Receipt.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
1+
import type {NullishDeep, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
22
import Onyx from 'react-native-onyx';
33
import * as API from '@libs/API';
44
import type {DetachReceiptParams, ReplaceReceiptParams} from '@libs/API/parameters';
@@ -17,6 +17,7 @@ import CONST from '@src/CONST';
1717
import ONYXKEYS from '@src/ONYXKEYS';
1818
import ROUTES from '@src/ROUTES';
1919
import type * as OnyxTypes from '@src/types/onyx';
20+
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
2021
import type {ReceiptSource} from '@src/types/onyx/Transaction';
2122
import {isEmptyObject} from '@src/types/utils/EmptyObject';
2223
import type {ReplaceReceipt} from '.';
@@ -253,29 +254,29 @@ function replaceReceipt({transactionID, file, source, state, transactionPolicy,
253254
});
254255
}
255256
if (currentSearchQueryJSON?.hash) {
257+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
258+
const optimisticSnapshotData: NullishDeep<SearchResultDataType> = {};
259+
optimisticSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = {
260+
receipt: receiptOptimistic,
261+
};
256262
optimisticData.push({
257263
onyxMethod: Onyx.METHOD.MERGE,
258264
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}`,
259-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
260265
value: {
261-
data: {
262-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {
263-
receipt: receiptOptimistic,
264-
},
265-
},
266+
data: optimisticSnapshotData,
266267
},
267268
});
268269

270+
// Initializing as an empty typed object to allow dynamic key assignment resolves TypeScript type inference issue
271+
const failureSnapshotData: NullishDeep<SearchResultDataType> = {};
272+
failureSnapshotData[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = {
273+
receipt: !isEmptyObject(oldReceipt) ? oldReceipt : null,
274+
};
269275
failureData.push({
270276
onyxMethod: Onyx.METHOD.MERGE,
271277
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}`,
272-
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
273278
value: {
274-
data: {
275-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {
276-
receipt: !isEmptyObject(oldReceipt) ? oldReceipt : null,
277-
},
278-
},
279+
data: failureSnapshotData,
279280
},
280281
});
281282
}

0 commit comments

Comments
 (0)