Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'IOU.js' lib to TypeScript #34092

Merged
merged 97 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
996ee26
Migrate Onyx.connect methods to TS
VickyStash Dec 28, 2023
b7af44a
Migrate simple functions
VickyStash Dec 28, 2023
519852e
Migrate startMoneyRequest_temporaryForRefactor and resetMoneyRequestI…
VickyStash Dec 28, 2023
e5f8cc3
Migrate buildOnyxDataForMoneyRequest function
VickyStash Dec 28, 2023
98a1e6b
Migrate getMoneyRequestInformation function
VickyStash Dec 28, 2023
19035e5
Fix failing Money request
VickyStash Dec 28, 2023
ad41a60
Migrate createDistanceRequest and requestMoney functions
VickyStash Dec 28, 2023
578cc50
Migrate startSplitBill function
VickyStash Dec 29, 2023
7b55077
Merge branch 'main' into ts-migration/iou
VickyStash Dec 29, 2023
8f0418d
Replace Split type with Participant
VickyStash Dec 29, 2023
417e173
Migrate completeSplitBill function
VickyStash Dec 29, 2023
6c962b3
Merge branch 'main' into ts-migration/iou
VickyStash Jan 2, 2024
ecdd7dd
Migrate getIOUReportID, navigateToNextPage and setMoneyRequestPartici…
VickyStash Jan 2, 2024
016c19e
Migrate approveMoneyRequest, submitReport, detachReceipt, replaceRece…
VickyStash Jan 2, 2024
012cd76
Migrate createSplitsAndOnyxData function
VickyStash Jan 2, 2024
041bde6
Merge branch 'main' into ts-migration/iou
VickyStash Jan 4, 2024
4711e1c
Migrate getReceiptError function; fix type imports after merging main
VickyStash Jan 4, 2024
372785b
Migrate splitBill and splitBillAndOpenReport functions
VickyStash Jan 4, 2024
4e7fab0
Migrate getUpdateMoneyRequestParams function
VickyStash Jan 4, 2024
cdcb7d5
Migrate updateMoneyRequestDate, updateDistanceRequest, editMoneyReque…
VickyStash Jan 4, 2024
c71ae90
Migrate setDraftSplitTransaction, editRegularMoneyRequest functions
VickyStash Jan 4, 2024
9aad84a
Migrate getSendMoneyParams function
VickyStash Jan 4, 2024
6357670
Migrate deleteMoneyRequest function
VickyStash Jan 8, 2024
992fdea
Migrate getPayMoneyRequestParams and payMoneyRequest functions
VickyStash Jan 8, 2024
6f658cd
Get rid of lodashGet and underscore usage
VickyStash Jan 8, 2024
4c7928b
Fix TS errors
VickyStash Jan 8, 2024
490f208
Merge branch 'main' into ts-migration/iou
VickyStash Jan 8, 2024
e60ebaa
TS fixes after merging main
VickyStash Jan 8, 2024
36420a7
Lint fixes
VickyStash Jan 8, 2024
d082cd4
Minor code improvements
VickyStash Jan 8, 2024
a21c11e
Merge branch 'main' into ts-migration/iou
VickyStash Jan 9, 2024
a8a7d64
TS updates after merging main
VickyStash Jan 9, 2024
fb6a0ad
Update updateIOUOwnerAndTotal function typing to get rid of assertions
VickyStash Jan 9, 2024
659f236
Get rid of nullable assertions in onyx update data
VickyStash Jan 9, 2024
5944ec6
Remove assertions, update buildOnyxDataForMoneyRequest typing
VickyStash Jan 9, 2024
c51b798
Add Split type
VickyStash Jan 9, 2024
a1eeacd
Add type params comments
VickyStash Jan 9, 2024
992e61d
ReportUtils file updates
VickyStash Jan 9, 2024
a488df6
Update receipt source type
VickyStash Jan 9, 2024
bd80055
Update errors types
VickyStash Jan 9, 2024
55d7cf0
Minor code improvements
VickyStash Jan 9, 2024
1ca2021
Merge branch 'main' into ts-migration/iou
VickyStash Jan 10, 2024
c059ca3
Remove TransactionDraft type, update deleteMoneyRequest typing after …
VickyStash Jan 10, 2024
ebfb6b9
Update createdChatReportActionID and createdIOUReportActionID type, u…
VickyStash Jan 10, 2024
185f26b
Minor code improvements
VickyStash Jan 10, 2024
e634a45
Merge branch 'main' into ts-migration/iou
VickyStash Jan 11, 2024
1af5ac6
Update replaceReceipt typing after merging main
VickyStash Jan 11, 2024
3495d18
Merge branch 'main' into ts-migration/iou
VickyStash Jan 12, 2024
d2d5d46
Onyx values type updates, minor code improvements
VickyStash Jan 12, 2024
038f646
Get rid of undefined checks
VickyStash Jan 12, 2024
dfbd3c3
Merge branch 'main' into ts-migration/iou
VickyStash Jan 15, 2024
9c838f9
Merge branch 'main' into ts-migration/iou
VickyStash Jan 15, 2024
679ce09
Migrate new cancelPayment function
VickyStash Jan 15, 2024
b85408f
Code improvement
VickyStash Jan 15, 2024
b8aedfc
Update getMoneyRequestInformation params order
VickyStash Jan 16, 2024
e48583d
Merge branch 'main' into ts-migration/iou
VickyStash Jan 16, 2024
7e7d697
Migrate to TS new parts of the code
VickyStash Jan 16, 2024
ff6fc29
Minor code improvements
VickyStash Jan 16, 2024
60a01e6
Merge branch 'main' into ts-migration/iou
VickyStash Jan 17, 2024
1297072
TS fixes after merging main
VickyStash Jan 17, 2024
1621e4b
Reuse existing types instead of creating new one
VickyStash Jan 17, 2024
5e48ce9
Code improvements
VickyStash Jan 17, 2024
c218af5
Update comments to go in one line
VickyStash Jan 17, 2024
ad37579
Merge branch 'main' into ts-migration/iou
VickyStash Jan 17, 2024
7043ef4
Remove not necessary anymore TODO
VickyStash Jan 17, 2024
c8afe19
Update Receipt source type, turn MERGE into SET
VickyStash Jan 17, 2024
8a8cd8d
Merge branch 'main' into ts-migration/iou
VickyStash Jan 18, 2024
9ba4d40
Remove unnecessary TODOs from IOU file
VickyStash Jan 18, 2024
76bb116
Merge branch 'main' into ts-migration/iou
VickyStash Jan 19, 2024
1bc5ac3
Merge branch 'main' into ts-migration/iou
VickyStash Jan 22, 2024
0b5eccd
Minor code improvements
VickyStash Jan 22, 2024
010769f
Merge branch 'main' into ts-migration/iou
VickyStash Jan 23, 2024
74eb199
Fix TS issues in the new part of code
VickyStash Jan 23, 2024
a3d4f7c
Merge branch 'main' into ts-migration/iou
VickyStash Jan 26, 2024
2dd0a90
Merge branch 'main' into ts-migration/iou
VickyStash Jan 29, 2024
4be927f
Migrate new functions to TS, move api typing to api folder
VickyStash Jan 29, 2024
1d18bea
Fix TS issues
VickyStash Jan 29, 2024
f6cef24
Update typing to fix ts errors
VickyStash Jan 29, 2024
e8ab203
Merge branch 'main' into ts-migration/iou
VickyStash Jan 30, 2024
93dd12a
TS fixes after merging main
VickyStash Jan 30, 2024
f78414e
Minor code improvement
VickyStash Jan 30, 2024
6de028e
Merge branch 'main' into ts-migration/iou
VickyStash Jan 30, 2024
b33dae6
Fix TS issues after merging main
VickyStash Jan 30, 2024
b97d482
Merge branch 'main' into ts-migration/iou
VickyStash Jan 31, 2024
1b2d85f
Merge branch 'main' into ts-migration/iou
VickyStash Feb 1, 2024
fe8ca0a
Apply TS fixes to the new code updates
VickyStash Feb 1, 2024
f533ee1
Update moneyRequestReportID default value
VickyStash Feb 2, 2024
39bc7f1
Merge branch 'main' into ts-migration/iou
VickyStash Feb 2, 2024
c2b9fc7
Minor TS fix
VickyStash Feb 2, 2024
a9a4018
Merge branch 'main' into ts-migration/iou
VickyStash Feb 2, 2024
54d0edf
Merge branch 'main' into ts-migration/iou
VickyStash Feb 2, 2024
59262ed
Merge branch 'main' into ts-migration/iou
VickyStash Feb 3, 2024
c445c5e
Lint fix
VickyStash Feb 3, 2024
de69ae8
Update comments
VickyStash Feb 3, 2024
a7b8fc1
Merge branch 'main' into ts-migration/iou
VickyStash Feb 5, 2024
88d805d
Get rid of removed screen type
VickyStash Feb 5, 2024
5359633
Merge branch 'main' into ts-migration/iou
VickyStash Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ type OnyxValues = {
[ONYXKEYS.COLLECTION.SECURITY_GROUP]: OnyxTypes.SecurityGroup;
[ONYXKEYS.COLLECTION.TRANSACTION]: OnyxTypes.Transaction;
[ONYXKEYS.COLLECTION.TRANSACTION_DRAFT]: OnyxTypes.Transaction;
[ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT]: OnyxTypes.Transaction;
[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS]: OnyxTypes.TransactionViolations;
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
[ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS]: OnyxTypes.RecentlyUsedTags;
[ONYXKEYS.COLLECTION.SELECTED_TAB]: string;
[ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT]: string;
Expand Down
7 changes: 1 addition & 6 deletions src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ type OfflineWithFeedbackProps = ChildrenProps & {

type StrikethroughProps = Partial<ChildrenProps> & {style: Array<ViewStyle | TextStyle | ImageStyle>};

function omitBy<T>(obj: Record<string, T> | undefined | null, predicate: (value: T) => boolean) {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars
return Object.fromEntries(Object.entries(obj ?? {}).filter(([_, value]) => !predicate(value)));
}

function OfflineWithFeedback({
pendingAction,
canDismissError = true,
Expand All @@ -84,7 +79,7 @@ function OfflineWithFeedback({

const hasErrors = isNotEmptyObject(errors ?? {});
// Some errors have a null message. This is used to apply opacity only and to avoid showing redundant messages.
const errorMessages = omitBy(errors, (e) => e === null);
const errorMessages = Object.fromEntries(Object.entries(errors ?? {}).filter((errorEntry): errorEntry is [string, string] => errorEntry[1] !== null));
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
const hasErrorMessages = isNotEmptyObject(errorMessages);
const isOfflinePendingAction = !!isOffline && !!pendingAction;
const isUpdateOrDeleteError = hasErrors && (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
Expand Down
2 changes: 2 additions & 0 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ function BaseTextInput(

const hasLabel = Boolean(label?.length);
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
const placeholderValue = !!prefixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const maxHeight = StyleSheet.flatten(containerStyles)?.maxHeight;
Expand Down
2 changes: 2 additions & 0 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ function BaseTextInput(

const hasLabel = Boolean(label?.length);
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
const newPlaceholder = !!prefixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const maxHeight = StyleSheet.flatten(containerStyles).maxHeight;
Expand Down
12 changes: 6 additions & 6 deletions src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CONST from '@src/CONST';
import type {TranslationFlatObject, TranslationPaths} from '@src/languages/types';
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
import type {ErrorFields, Errors, ErrorsObject} from '@src/types/onyx/OnyxCommon';
import type Response from '@src/types/onyx/Response';
import DateUtils from './DateUtils';
import * as Localize from './Localize';
Expand Down Expand Up @@ -38,23 +38,23 @@ function getAuthenticateErrorMessage(response: Response): keyof TranslationFlatO
* Method used to get an error object with microsecond as the key.
* @param error - error key or message to be saved
*/
function getMicroSecondOnyxError(error: string): Record<number, string> {
function getMicroSecondOnyxError(error: string | null): Errors {
return {[DateUtils.getMicroseconds()]: error};
}

/**
* Method used to get an error object with microsecond as the key and an object as the value.
* @param error - error key or message to be saved
*/
function getMicroSecondOnyxErrorObject(error: Record<string, string>): Record<number, Record<string, string>> {
function getMicroSecondOnyxErrorObject(error: Errors): ErrorsObject {
return {[DateUtils.getMicroseconds()]: error};
}

type OnyxDataWithErrors = {
errors?: Errors;
};

function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: TOnyxData): string {
function getLatestErrorMessage<TOnyxData extends OnyxDataWithErrors>(onyxData: TOnyxData): string | null {
const errors = onyxData.errors ?? {};

if (Object.keys(errors).length === 0) {
Expand All @@ -70,7 +70,7 @@ type OnyxDataWithErrorFields = {
errorFields?: ErrorFields;
};

function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Record<string, string> {
function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Errors {
const errorsForField = onyxData.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
Expand All @@ -82,7 +82,7 @@ function getLatestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData
return {[key]: errorsForField[key]};
}

function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Record<string, string> {
function getEarliestErrorField<TOnyxData extends OnyxDataWithErrorFields>(onyxData: TOnyxData, fieldName: string): Errors {
const errorsForField = onyxData.errorFields?.[fieldName] ?? {};

if (Object.keys(errorsForField).length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ function calculateAmount(numberOfParticipants: number, total: number, currency:
*
* @param isDeleting - whether the user is deleting the request
*/
function updateIOUOwnerAndTotal(iouReport: OnyxEntry<Report>, actorAccountID: number, amount: number, currency: string, isDeleting = false): OnyxEntry<Report> {
function updateIOUOwnerAndTotal<TReport extends OnyxEntry<Report>>(iouReport: TReport, actorAccountID: number, amount: number, currency: string, isDeleting = false): TReport {
if (currency !== iouReport?.currency) {
return iouReport;
}

// Make a copy so we don't mutate the original object
const iouReportUpdate: Report = {...iouReport};
const iouReportUpdate = {...iouReport};

// Let us ensure a valid value before updating the total amount.
iouReportUpdate.total = iouReportUpdate.total ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function isPendingDeletePolicy(policy: OnyxEntry<Policy>): boolean {
return policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

function isPaidGroupPolicy(policy: OnyxEntry<Policy>): boolean {
function isPaidGroupPolicy(policy: OnyxEntry<Policy> | EmptyObject): boolean {
return policy?.type === CONST.POLICY.TYPE.TEAM || policy?.type === CONST.POLICY.TYPE.CORPORATE;
}

Expand Down
8 changes: 5 additions & 3 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type MemberChangeMessageRoomReferenceElement = {

type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

type ActionsToMerge = Record<string, ReportAction | null>;

const allReports: OnyxCollection<Report> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -442,17 +444,17 @@ function replaceBaseURL(reportAction: ReportAction): ReportAction {

/**
*/
function getLastVisibleAction(reportID: string, actionsToMerge: ReportActions = {}): OnyxEntry<ReportAction> {
function getLastVisibleAction(reportID: string, actionsToMerge: ActionsToMerge = {}): OnyxEntry<ReportAction> {
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
const reportActions = Object.values(OnyxUtils.fastMerge(allReportActions?.[reportID] ?? {}, actionsToMerge));
const visibleReportActions = Object.values(reportActions ?? {}).filter((action) => shouldReportActionBeVisibleAsLastAction(action));
const visibleReportActions = Object.values(reportActions ?? {}).filter((action): action is ReportAction => shouldReportActionBeVisibleAsLastAction(action));
const sortedReportActions = getSortedReportActions(visibleReportActions, true);
if (sortedReportActions.length === 0) {
return null;
}
return sortedReportActions[0];
}

function getLastVisibleMessage(reportID: string, actionsToMerge: ReportActions = {}): LastVisibleMessage {
function getLastVisibleMessage(reportID: string, actionsToMerge: ActionsToMerge = {}): LastVisibleMessage {
const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge);
const message = lastVisibleAction?.message?.[0];

Expand Down
113 changes: 34 additions & 79 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import type {ParentNavigationSummaryParams, TranslationPaths} from '@src/languag
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Beta, Login, PersonalDetails, PersonalDetailsList, Policy, Report, ReportAction, ReportMetadata, Session, Transaction} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {IOUMessage, OriginalMessageActionName, OriginalMessageCreated} from '@src/types/onyx/OriginalMessage';
import type {Status} from '@src/types/onyx/PersonalDetails';
import type {NotificationPreference} from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type {Receipt, WaypointCollection} from '@src/types/onyx/Transaction';
import type {Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -64,20 +65,6 @@ type ExpenseOriginalMessage = {
oldBillable?: string;
};

type Participant = {
accountID: number;
alternateText: string;
firstName: string;
icons: Icon[];
keyForList: string;
lastName: string;
login: string;
phoneNumber: string;
searchText: string;
selected: boolean;
text: string;
};

type SpendBreakdown = {
nonReimbursableSpend: number;
reimbursableSpend: number;
Expand Down Expand Up @@ -139,35 +126,14 @@ type OptimisticIOUReportAction = Pick<
| 'whisperedToAccountIDs'
>;

type OptimisticReportPreview = Pick<
ReportAction,
| 'actionName'
| 'reportActionID'
| 'pendingAction'
| 'originalMessage'
| 'message'
| 'created'
| 'actorAccountID'
| 'childMoneyRequestCount'
| 'childLastMoneyRequestComment'
| 'childRecentReceiptTransactionIDs'
| 'childReportID'
| 'whisperedToAccountIDs'
> & {reportID?: string; accountID?: number};

type UpdateReportPreview = Pick<
ReportAction,
'created' | 'message' | 'childLastMoneyRequestComment' | 'childMoneyRequestCount' | 'childRecentReceiptTransactionIDs' | 'whisperedToAccountIDs'
>;

type ReportRouteParams = {
reportID: string;
isSubReportPageRoute: boolean;
};

type ReportOfflinePendingActionAndErrors = {
addWorkspaceRoomOrChatPendingAction: PendingAction | undefined;
addWorkspaceRoomOrChatErrors: Record<string, string> | null | undefined;
addWorkspaceRoomOrChatErrors: Errors | null | undefined;
};

type OptimisticApprovedReportAction = Pick<
Expand Down Expand Up @@ -197,6 +163,8 @@ type OptimisticChatReport = Pick<
Report,
| 'type'
| 'chatType'
| 'chatReportID'
| 'iouReportID'
| 'isOwnPolicyExpenseChat'
| 'isPinned'
| 'lastActorAccountID'
Expand All @@ -208,6 +176,7 @@ type OptimisticChatReport = Pick<
| 'notificationPreference'
| 'oldPolicyName'
| 'ownerAccountID'
| 'pendingFields'
| 'parentReportActionID'
| 'parentReportID'
| 'participantAccountIDs'
Expand Down Expand Up @@ -277,23 +246,21 @@ type OptimisticTaskReport = Pick<
| 'lastVisibleActionCreated'
>;

type TransactionDetails =
| {
created: string;
amount: number;
currency: string;
merchant: string;
waypoints?: WaypointCollection;
comment: string;
category: string;
billable: boolean;
tag: string;
mccGroup?: ValueOf<typeof CONST.MCC_GROUPS>;
cardID: number;
originalAmount: number;
originalCurrency: string;
}
| undefined;
type TransactionDetails = {
created: string;
amount: number;
currency: string;
merchant: string;
waypoints?: WaypointCollection | string;
comment: string;
category: string;
billable: boolean;
tag: string;
mccGroup?: ValueOf<typeof CONST.MCC_GROUPS>;
cardID: number;
originalAmount: number;
originalCurrency: string;
};

type OptimisticIOUReport = Pick<
Report,
Expand Down Expand Up @@ -433,7 +400,7 @@ Onyx.connect({
},
});

function getChatType(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.CHAT_TYPE> | undefined {
function getChatType(report: OnyxEntry<Report> | Participant): ValueOf<typeof CONST.REPORT.CHAT_TYPE> | undefined {
return report?.chatType;
}

Expand Down Expand Up @@ -706,7 +673,7 @@ function isUserCreatedPolicyRoom(report: OnyxEntry<Report>): boolean {
/**
* Whether the provided report is a Policy Expense chat.
*/
function isPolicyExpenseChat(report: OnyxEntry<Report>): boolean {
function isPolicyExpenseChat(report: OnyxEntry<Report> | Participant): boolean {
return getChatType(report) === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT || (report?.isPolicyExpenseChat ?? false);
}

Expand Down Expand Up @@ -1825,7 +1792,7 @@ function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<
* into a flat object. Used for displaying transactions and sending them in API commands
*/

function getTransactionDetails(transaction: OnyxEntry<Transaction>, createdDateFormat: string = CONST.DATE.FNS_FORMAT_STRING): TransactionDetails {
function getTransactionDetails(transaction: OnyxEntry<Transaction>, createdDateFormat: string = CONST.DATE.FNS_FORMAT_STRING): TransactionDetails | undefined {
if (!transaction) {
return;
}
Expand Down Expand Up @@ -2156,7 +2123,7 @@ function getReportPreviewMessage(
*
* At the moment, we only allow changing one transaction field at a time.
*/
function getModifiedExpenseOriginalMessage(oldTransaction: OnyxEntry<Transaction>, transactionChanges: ExpenseOriginalMessage, isFromExpenseReport: boolean): ExpenseOriginalMessage {
function getModifiedExpenseOriginalMessage(oldTransaction: OnyxEntry<Transaction>, transactionChanges: TransactionChanges, isFromExpenseReport: boolean): ExpenseOriginalMessage {
const originalMessage: ExpenseOriginalMessage = {};
// Remark: Comment field is the only one which has new/old prefixes for the keys (newComment/ oldComment),
// all others have old/- pattern such as oldCreated/created
Expand Down Expand Up @@ -2697,7 +2664,7 @@ function buildOptimisticIOUReportAction(
comment: string,
participants: Participant[],
transactionID: string,
paymentType: DeepValueOf<typeof CONST.IOU.PAYMENT_TYPE>,
paymentType?: DeepValueOf<typeof CONST.IOU.PAYMENT_TYPE>,
iouReportID = '',
isSettlingUp = false,
isSendMoneyFlow = false,
Expand Down Expand Up @@ -2742,8 +2709,8 @@ function buildOptimisticIOUReportAction(
originalMessage.participantAccountIDs = currentUserAccountID ? [currentUserAccountID] : [];
} else {
originalMessage.participantAccountIDs = currentUserAccountID
? [currentUserAccountID, ...participants.map((participant) => participant.accountID)]
: participants.map((participant) => participant.accountID);
? [currentUserAccountID, ...participants.map((participant) => participant.accountID ?? -1)]
: participants.map((participant) => participant.accountID ?? -1);
}
}

Expand Down Expand Up @@ -2885,13 +2852,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string,
* @param [comment] - User comment for the IOU.
* @param [transaction] - optimistic first transaction of preview
*/
function buildOptimisticReportPreview(
chatReport: OnyxEntry<Report>,
iouReport: OnyxEntry<Report>,
comment = '',
transaction: OnyxEntry<Transaction> = null,
childReportID?: string,
): OptimisticReportPreview {
function buildOptimisticReportPreview(chatReport: OnyxEntry<Report>, iouReport: Report, comment = '', transaction: OnyxEntry<Transaction> = null, childReportID?: string): ReportAction {
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction);
const message = getReportPreviewMessage(iouReport);
Expand Down Expand Up @@ -2928,9 +2889,9 @@ function buildOptimisticReportPreview(
* Builds an optimistic modified expense action with a randomly generated reportActionID.
*/
function buildOptimisticModifiedExpenseReportAction(
transactionThread: OnyxEntry<Transaction>,
transactionThread: OnyxEntry<Report>,
oldTransaction: OnyxEntry<Transaction>,
transactionChanges: ExpenseOriginalMessage,
transactionChanges: TransactionChanges,
isFromExpenseReport: boolean,
): OptimisticModifiedExpenseReportAction {
const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport);
Expand Down Expand Up @@ -2971,13 +2932,7 @@ function buildOptimisticModifiedExpenseReportAction(
* @param [transaction] - optimistic newest transaction of a report preview
*
*/
function updateReportPreview(
iouReport: OnyxEntry<Report>,
reportPreviewAction: OnyxEntry<ReportAction>,
isPayRequest = false,
comment = '',
transaction: OnyxEntry<Transaction> = null,
): UpdateReportPreview {
function updateReportPreview(iouReport: OnyxEntry<Report>, reportPreviewAction: ReportAction, isPayRequest = false, comment = '', transaction: OnyxEntry<Transaction> = null): ReportAction {
const hasReceipt = TransactionUtils.hasReceipt(transaction);
const recentReceiptTransactions = reportPreviewAction?.childRecentReceiptTransactionIDs ?? {};
const transactionsToKeep = TransactionUtils.getRecentTransactions(recentReceiptTransactions);
Expand Down Expand Up @@ -3925,7 +3880,7 @@ function isValidReportIDFromPath(reportIDFromPath: string): boolean {
/**
* Return the errors we have when creating a chat or a workspace room
*/
function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Record<string, string> | null | undefined {
function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Errors | null | undefined {
// We are either adding a workspace room, or we're creating a chat, it isn't possible for both of these to have errors for the same report at the same time, so
// simply looking up the first truthy value will get the relevant property if it's set.
return report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat;
Expand Down Expand Up @@ -4535,4 +4490,4 @@ export {
shouldDisableThread,
};

export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction};
export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails};
Loading
Loading