Skip to content

A local-first personal finance app

Address some more low-hanging fruit for ts-strict-ignore (#6992)

Julian Dominguez-Schatze8f6ceeb98b9
diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx
index 264d2ca813..d42f907c1d 100644
--- a/packages/desktop-client/src/components/App.tsx
+++ b/packages/desktop-client/src/components/App.tsx
@@ -1,4 +1,3 @@
-// @ts-strict-ignore
import React, { useEffect, useState } from 'react';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
@@ -63,7 +62,7 @@ function AppInner() {
}, []);
useEffect(() => {
- const maybeUpdate = async <T,>(cb?: () => T): Promise<T> => {
+ const maybeUpdate = async <T,>(cb?: () => T): Promise<T | void> => {
if (global.Actual.isUpdateReadyForDownload()) {
dispatch(
setAppState({
diff --git a/packages/desktop-client/src/components/budget/BudgetTable.tsx b/packages/desktop-client/src/components/budget/BudgetTable.tsx
index ab660bdd28..8c727035aa 100644
--- a/packages/desktop-client/src/components/budget/BudgetTable.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetTable.tsx
@@ -96,7 +96,7 @@ export function BudgetTable(props: BudgetTableProps) {
const _onReorderCategory = (
id: string,
- dropPos: DropPosition,
+ dropPos: DropPosition | null,
targetId: string,
) => {
const isGroup = !!categoryGroups.find(g => g.id === targetId);
@@ -137,7 +137,7 @@ export function BudgetTable(props: BudgetTableProps) {
const _onReorderGroup = (
id: string,
- dropPos: DropPosition,
+ dropPos: DropPosition | null,
targetId: string,
) => {
const [expenseGroups] = separateGroups(categoryGroups); // exclude Income group from sortable groups to fix off-by-one error
diff --git a/packages/desktop-client/src/components/budget/util.ts b/packages/desktop-client/src/components/budget/util.ts
index 61fc8cb75e..d4a16b940e 100644
--- a/packages/desktop-client/src/components/budget/util.ts
+++ b/packages/desktop-client/src/components/budget/util.ts
@@ -127,7 +127,7 @@ export function makeAmountFullStyle(
export function findSortDown<T extends { id: string }>(
arr: T[],
- pos: DropPosition,
+ pos: DropPosition | null,
targetId: string,
) {
if (pos === 'top') {
@@ -151,7 +151,7 @@ export function findSortDown<T extends { id: string }>(
export function findSortUp<T extends { id: string }>(
arr: T[],
- pos: DropPosition,
+ pos: DropPosition | null,
targetId: string,
) {
if (pos === 'bottom') {
diff --git a/packages/desktop-client/src/components/sidebar/Accounts.tsx b/packages/desktop-client/src/components/sidebar/Accounts.tsx
index 8912c9f263..53beff3fc0 100644
--- a/packages/desktop-client/src/components/sidebar/Accounts.tsx
+++ b/packages/desktop-client/src/components/sidebar/Accounts.tsx
@@ -57,16 +57,16 @@ export function Accounts() {
async function onReorder(
id: string,
- dropPos: 'top' | 'bottom',
- targetId: unknown,
+ dropPos: 'top' | 'bottom' | null,
+ targetId: string,
) {
- let targetIdToMove = targetId;
+ let targetIdToMove: string | null = targetId;
if (dropPos === 'bottom') {
const idx = accounts.findIndex(a => a.id === targetId) + 1;
targetIdToMove = idx < accounts.length ? accounts[idx].id : null;
}
- moveAccount.mutate({ id, targetId: targetIdToMove as string });
+ moveAccount.mutate({ id, targetId: targetIdToMove });
}
const onToggleClosedAccounts = () => {
diff --git a/packages/desktop-client/src/components/sort.tsx b/packages/desktop-client/src/components/sort.tsx
index c502deb45c..2933c7c1ab 100644
--- a/packages/desktop-client/src/components/sort.tsx
+++ b/packages/desktop-client/src/components/sort.tsx
@@ -1,4 +1,3 @@
-// @ts-strict-ignore
import React, {
createContext,
useContext,
@@ -7,7 +6,6 @@ import React, {
useRef,
useState,
} from 'react';
-import type { Context } from 'react';
import { useDrag, useDrop } from 'react-dnd';
import { theme } from '@actual-app/components/theme';
@@ -75,7 +73,7 @@ export function useDraggable<T>({
export type OnDropCallback = (
id: string,
- dropPos: DropPosition,
+ dropPos: DropPosition | null,
targetId: string,
) => Promise<void> | void;
@@ -94,7 +92,7 @@ export function useDroppable<T extends { id: string }>({
onDrop,
onLongHover,
}: UseDroppableArgs) {
- const ref = useRef(null);
+ const ref = useRef<HTMLDivElement | null>(null);
const onLongHoverRef = useRef(onLongHover);
const [dropPos, setDropPos] = useState<DropPosition | null>(null);
@@ -108,10 +106,12 @@ export function useDroppable<T extends { id: string }>({
onDrop(item.id, dropPos, id);
},
hover(_, monitor) {
+ if (!ref.current) return;
const hoverBoundingRect = ref.current.getBoundingClientRect();
const hoverMiddleY =
(hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
const clientOffset = monitor.getClientOffset();
+ if (!clientOffset) return;
const hoverClientY = clientOffset.y - hoverBoundingRect.top;
const pos: DropPosition = hoverClientY < hoverMiddleY ? 'top' : 'bottom';
@@ -147,8 +147,7 @@ export function useDroppable<T extends { id: string }>({
}
type ItemPosition = 'first' | 'last' | null;
-export const DropHighlightPosContext: Context<ItemPosition> =
- createContext(null);
+export const DropHighlightPosContext = createContext<ItemPosition>(null);
type DropHighlightProps = {
pos: DropPosition;
diff --git a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
index ad661595d3..85a4271ecd 100644
--- a/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
+++ b/packages/desktop-client/src/hooks/useAccountPreviewTransactions.ts
@@ -40,13 +40,13 @@ export function useAccountPreviewTransactions({
const payeesById = useMemo(() => groupById(payees), [payees]);
const getPayeeByTransferAccount = useCallback(
- (transferAccountId?: AccountEntity['id']) =>
+ (transferAccountId?: AccountEntity['id'] | null) =>
payees.find(p => p.transfer_acct === transferAccountId) || null,
[payees],
);
const getTransferAccountByPayee = useCallback(
- (payeeId?: PayeeEntity['id']) => {
+ (payeeId?: PayeeEntity['id'] | null) => {
if (!payeeId) {
return null;
}
@@ -145,10 +145,10 @@ type InverseBasedOnAccountProps = {
startingBalance: IntegerAmount;
runningBalances: Map<TransactionEntity['id'], IntegerAmount>;
getPayeeByTransferAccount: (
- transferAccountId?: AccountEntity['id'],
+ transferAccountId?: AccountEntity['id'] | null,
) => PayeeEntity | null;
getTransferAccountByPayee: (
- payeeId?: PayeeEntity['id'],
+ payeeId?: PayeeEntity['id'] | null,
) => AccountEntity | null;
};
diff --git a/packages/desktop-client/src/i18n.ts b/packages/desktop-client/src/i18n.ts
index c9be051555..cc4a5fc187 100644
--- a/packages/desktop-client/src/i18n.ts
+++ b/packages/desktop-client/src/i18n.ts
@@ -63,7 +63,7 @@ const resolveLanguage = (language: string) => {
return undefined;
};
-export const setI18NextLanguage = (language: string) => {
+export const setI18NextLanguage = (language: string | null) => {
const defaultLanguages = Array.isArray(navigator.languages)
? navigator.languages
: [navigator.language || 'en'];
diff --git a/packages/loot-core/src/platform/server/fs/index.web.test.ts b/packages/loot-core/src/platform/server/fs/index.web.test.ts
index 311b496199..2df8f65fc9 100644
--- a/packages/loot-core/src/platform/server/fs/index.web.test.ts
+++ b/packages/loot-core/src/platform/server/fs/index.web.test.ts
@@ -1,4 +1,3 @@
-// @ts-strict-ignore
import 'fake-indexeddb/auto';
import { IDBFactory } from 'fake-indexeddb';
diff --git a/packages/loot-core/src/server/accounts/payees.ts b/packages/loot-core/src/server/accounts/payees.ts
index 695a7150c9..74e6d1e1a4 100644
--- a/packages/loot-core/src/server/accounts/payees.ts
+++ b/packages/loot-core/src/server/accounts/payees.ts
@@ -1,7 +1,6 @@
-// @ts-strict-ignore
import * as db from '../db';
-export async function createPayee(description) {
+export async function createPayee(description: string) {
// Check to make sure no payee already exists with exactly the same
// name
const row = await db.first<Pick<db.DbPayee, 'id'>>(
diff --git a/packages/loot-core/src/server/api.ts b/packages/loot-core/src/server/api.ts
index 20c14ecd33..4b2cf60d3e 100644
--- a/packages/loot-core/src/server/api.ts
+++ b/packages/loot-core/src/server/api.ts
@@ -224,7 +224,7 @@ handlers['api/download-budget'] = async function ({ syncId, password }) {
await handlers['load-budget']({ id: localBudget.id });
const result = await handlers['sync-budget']();
if (result.error) {
- throw new Error(getSyncError(result.error, localBudget.id));
+ throw new Error(getSyncError(result.error.reason, localBudget.id));
}
return;
}
@@ -253,7 +253,7 @@ handlers['api/sync'] = async function () {
const { id } = prefs.getPrefs();
const result = await handlers['sync-budget']();
if (result.error) {
- throw new Error(getSyncError(result.error, id));
+ throw new Error(getSyncError(result.error.reason, id));
}
};
diff --git a/packages/loot-core/src/shared/errors.ts b/packages/loot-core/src/shared/errors.ts
index c927343411..c5e484d13e 100644
--- a/packages/loot-core/src/shared/errors.ts
+++ b/packages/loot-core/src/shared/errors.ts
@@ -1,12 +1,11 @@
-// @ts-strict-ignore
import { t } from 'i18next';
-export function getUploadError({
- reason,
- meta,
-}: {
+
+type ErrorWithMeta = {
reason: string;
meta?: unknown;
-}) {
+};
+
+export function getUploadError({ reason, meta }: ErrorWithMeta) {
switch (reason) {
case 'unauthorized':
return t('You are not logged in.');
@@ -89,11 +88,11 @@ export function getDownloadError({
}
}
-export function getCreateKeyError(error) {
+export function getCreateKeyError(error: ErrorWithMeta) {
return getUploadError(error);
}
-export function getTestKeyError({ reason }) {
+export function getTestKeyError({ reason }: ErrorWithMeta) {
switch (reason) {
case 'network':
return t(
@@ -112,7 +111,7 @@ export function getTestKeyError({ reason }) {
}
}
-export function getSyncError(error, id) {
+export function getSyncError(error: string, id: string) {
if (error === 'out-of-sync-migrations' || error === 'out-of-sync-data') {
return t('This budget cannot be loaded with this version of the app.');
} else if (error === 'budget-not-found') {
diff --git a/packages/loot-core/src/types/models/import-transaction.ts b/packages/loot-core/src/types/models/import-transaction.ts
index aac4fc3416..c9779fb09a 100644
--- a/packages/loot-core/src/types/models/import-transaction.ts
+++ b/packages/loot-core/src/types/models/import-transaction.ts
@@ -15,7 +15,7 @@ export type ImportTransactionEntity = {
/** In a create/import request, this overrides payee_name.
* Should be an existing payee ID */
- payee?: string;
+ payee?: string | null;
/** If given, a payee will be created with this name.
* If this matches an already existing payee, that payee will be used.
diff --git a/packages/loot-core/src/types/models/transaction.ts b/packages/loot-core/src/types/models/transaction.ts
index b62dbb954c..908ef9a595 100644
--- a/packages/loot-core/src/types/models/transaction.ts
+++ b/packages/loot-core/src/types/models/transaction.ts
@@ -13,7 +13,7 @@ export type TransactionEntity = {
account: AccountEntity['id'];
category?: CategoryEntity['id'];
amount: IntegerAmount;
- payee?: PayeeEntity['id'];
+ payee?: PayeeEntity['id'] | null;
notes?: string;
date: string;
imported_id?: string;
diff --git a/packages/loot-core/typings/window.ts b/packages/loot-core/typings/window.ts
index e5f21ed059..e9387a5d3f 100644
--- a/packages/loot-core/typings/window.ts
+++ b/packages/loot-core/typings/window.ts
@@ -1,5 +1,9 @@
-// @ts-strict-ignore
-export {};
+import type EventEmitter from 'events';
+
+export type IpcClient = {
+ on: EventEmitter['on'];
+ emit: (name: string, data: unknown) => void;
+};
type FileDialogOptions = {
properties?: Array<'openFile' | 'openDirectory'>;
@@ -28,7 +32,7 @@ type Actual = {
newDirectory: string,
) => Promise<void>;
applyAppUpdate: () => Promise<void>;
- ipcConnect: (callback: (client) => void) => void;
+ ipcConnect: (callback: (client: IpcClient) => void) => void;
getServerSocket: () => Promise<Worker | null>;
setTheme: (theme: string) => void;
logToTerminal: (...args: unknown[]) => void;
diff --git a/upcoming-release-notes/6992.md b/upcoming-release-notes/6992.md
new file mode 100644
index 0000000000..f0c7a059ca
--- /dev/null
+++ b/upcoming-release-notes/6992.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [jfdoming]
+---
+
+Address some more low-hanging fruit for ts-strict-ignore