diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx index 1ce83b9089..bc6331e269 100644 --- a/packages/desktop-client/src/components/accounts/Account.tsx +++ b/packages/desktop-client/src/components/accounts/Account.tsx @@ -153,11 +153,11 @@ function EmptyMessage({ onAdd }: EmptyMessageProps) { } type AllTransactionsProps = { - account?: AccountEntity; + account?: AccountEntity | undefined; transactions: TransactionEntity[]; balances: Record | null; - showBalances?: boolean; - filtered?: boolean; + showBalances?: boolean | undefined; + filtered?: boolean | undefined; children: ( transactions: TransactionEntity[], balances: Record | null, @@ -265,7 +265,12 @@ function getField(field?: string) { } type AccountInternalProps = { - accountId?: AccountEntity['id'] | 'onbudget' | 'offbudget' | 'uncategorized'; + accountId?: + | AccountEntity['id'] + | 'onbudget' + | 'offbudget' + | 'uncategorized' + | undefined; filterConditions: RuleConditionEntity[]; showBalances?: boolean; setShowBalances: (newValue: boolean) => void; @@ -280,7 +285,7 @@ type AccountInternalProps = { newTransactions: Array; matchedTransactions: Array; splitsExpandedDispatch: ReturnType['dispatch']; - expandSplits?: boolean; + expandSplits?: boolean | undefined; savedFilters: TransactionFilterEntity[]; onBatchEdit: ReturnType['onBatchEdit']; onBatchDuplicate: ReturnType< @@ -306,7 +311,7 @@ type AccountInternalProps = { type AccountInternalState = { search: string; filterConditions: ConditionEntity[]; - filterId?: SavedFilter; + filterId?: SavedFilter | undefined; filterConditionsOp: 'and' | 'or'; loading: boolean; workingHard: boolean; @@ -314,10 +319,10 @@ type AccountInternalState = { transactions: TransactionEntity[]; transactionCount: number; transactionsFiltered?: boolean; - showBalances?: boolean; + showBalances?: boolean | undefined; balances: Record | null; - showCleared?: boolean; - prevShowCleared?: boolean; + showCleared?: boolean | undefined; + prevShowCleared?: boolean | undefined; showReconciled: boolean; editingName: boolean; nameError: string; @@ -326,8 +331,8 @@ type AccountInternalState = { sort: { ascDesc: 'asc' | 'desc'; field: string; - prevField?: string; - prevAscDesc?: 'asc' | 'desc'; + prevField?: string | undefined; + prevAscDesc?: 'asc' | 'desc' | undefined; } | null; filteredAmount: null | number; }; diff --git a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts index d66e768722..34b1201ec7 100644 --- a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts +++ b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts @@ -11,7 +11,7 @@ import { useAccounts } from './useAccounts'; import { usePayees } from './usePayees'; type UseAccountPreviewTransactionsProps = { - accountId?: AccountEntity['id']; + accountId?: AccountEntity['id'] | undefined; }; type UseAccountPreviewTransactionsResult = { @@ -73,25 +73,26 @@ function accountPreview({ }: AccountPreviewProps): TransactionEntity[] { return transactions.map(transaction => { const inverse = transaction.account !== accountId; + const subtransactions = transaction.subtransactions?.map(st => ({ + ...st, + amount: inverse ? -st.amount : st.amount, + payee: + (inverse ? getPayeeByTransferAccount(st.account)?.id : st.payee) || '', + account: inverse + ? getTransferAccountByPayee(st.payee)?.id || '' + : st.account, + })); return { ...transaction, amount: inverse ? -transaction.amount : transaction.amount, - payee: inverse - ? getPayeeByTransferAccount(transaction.account)?.id || '' - : transaction.payee, + payee: + (inverse + ? getPayeeByTransferAccount(transaction.account)?.id + : transaction.payee) || '', account: inverse ? getTransferAccountByPayee(transaction.payee)?.id || '' : transaction.account, - subtransactions: transaction.subtransactions?.map(st => ({ - ...st, - amount: inverse ? -st.amount : st.amount, - payee: inverse - ? getPayeeByTransferAccount(st.account)?.id || '' - : st.payee, - account: inverse - ? getTransferAccountByPayee(st.payee)?.id || '' - : st.account, - })), + ...(subtransactions && { subtransactions }), }; }); } diff --git a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts b/packages/desktop-client/src/hooks/useTransactionBatchActions.ts index ff612ac4c8..66824ec64d 100644 --- a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts +++ b/packages/desktop-client/src/hooks/useTransactionBatchActions.ts @@ -42,7 +42,7 @@ type BatchDeleteProps = { type BatchLinkScheduleProps = { ids: Array; - account?: AccountEntity; + account?: AccountEntity | undefined; onSuccess?: ( ids: Array, schedule: ScheduleEntity, diff --git a/packages/loot-core/src/client/state-types/modals.d.ts b/packages/loot-core/src/client/state-types/modals.d.ts index 04065adada..0682072951 100644 --- a/packages/loot-core/src/client/state-types/modals.d.ts +++ b/packages/loot-core/src/client/state-types/modals.d.ts @@ -148,7 +148,7 @@ type FinanceModals = { 'category-autocomplete': { categoryGroups?: CategoryGroupEntity[]; onSelect: (categoryId: string, categoryName: string) => void; - month?: string; + month?: string | undefined; showHiddenCategories?: boolean; onClose?: () => void; }; @@ -315,7 +315,7 @@ type FinanceModals = { confirmReason: string; }; 'confirm-transaction-delete': { - message?: string; + message?: string | undefined; onConfirm: () => void; }; 'edit-user': { diff --git a/upcoming-release-notes/4189.md b/upcoming-release-notes/4189.md new file mode 100644 index 0000000000..bd49ccb116 --- /dev/null +++ b/upcoming-release-notes/4189.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [jfdoming] +--- + +Make `Account.tsx` compatible with `exactOptionalPropertyTypes`