A local-first personal finance app
:recycle: (typescript) move some files to strict mode (#2403)
Matiss Janis Aboltinsb700aee87de1
diff --git a/packages/desktop-client/src/components/FatalError.tsx b/packages/desktop-client/src/components/FatalError.tsxindex ebed6c72ee..9b96ba0fe5 100644--- a/packages/desktop-client/src/components/FatalError.tsx+++ b/packages/desktop-client/src/components/FatalError.tsx@@ -166,7 +166,9 @@ export function FatalError({ buttonText, error }: FatalErrorProps) {>{showSimpleRender ? <RenderSimple error={error} /> : <RenderUIError />}<Paragraph>- <Button onClick={() => window.Actual.relaunch()}>{buttonText}</Button>+ <Button onClick={() => window.Actual?.relaunch()}>+ {buttonText}+ </Button></Paragraph><Paragraph isLast={true} style={{ fontSize: 11 }}><LinkButton onClick={() => setShowError(true)}>Show Error</LinkButton>diff --git a/packages/desktop-client/src/components/GlobalKeys.ts b/packages/desktop-client/src/components/GlobalKeys.tsindex 1109e4250c..a6e785347f 100644--- a/packages/desktop-client/src/components/GlobalKeys.ts+++ b/packages/desktop-client/src/components/GlobalKeys.ts@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport { useEffect } from 'react';import * as Platform from 'loot-core/src/client/platform';@@ -8,7 +7,7 @@ import { useNavigate } from '../hooks/useNavigate';export function GlobalKeys() {const navigate = useNavigate();useEffect(() => {- const handleKeys = e => {+ const handleKeys = (e: KeyboardEvent) => {if (Platform.isBrowser) {return;}diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsxindex 48f30a99a4..18a560f997 100644--- a/packages/desktop-client/src/components/accounts/Account.jsx+++ b/packages/desktop-client/src/components/accounts/Account.jsx@@ -470,7 +470,7 @@ class AccountInternal extends PureComponent {const categories = await this.props.getCategories();if (account) {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({filters: [{name: 'Financial Files',@@ -502,7 +502,7 @@ class AccountInternal extends PureComponent {accountName && accountName.replace(/[()]/g, '').replace(/\s+/g, '-');const filename = `${normalizedName || 'transactions'}.csv`;- window.Actual.saveFile(+ window.Actual?.saveFile(exportedTransactions,filename,'Export Transactions',diff --git a/packages/desktop-client/src/components/manager/ImportActual.tsx b/packages/desktop-client/src/components/manager/ImportActual.tsxindex 665c4ea8ff..a6863deb53 100644--- a/packages/desktop-client/src/components/manager/ImportActual.tsx+++ b/packages/desktop-client/src/components/manager/ImportActual.tsx@@ -38,7 +38,7 @@ export function ImportActual({ modalProps }: ImportProps) {const [importing, setImporting] = useState(false);async function onImport() {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({properties: ['openFile'],filters: [{ name: 'actual', extensions: ['zip', 'blob'] }],});diff --git a/packages/desktop-client/src/components/manager/ImportYNAB4.tsx b/packages/desktop-client/src/components/manager/ImportYNAB4.tsxindex f95de762c2..338a5dd5e2 100644--- a/packages/desktop-client/src/components/manager/ImportYNAB4.tsx+++ b/packages/desktop-client/src/components/manager/ImportYNAB4.tsx@@ -30,7 +30,7 @@ export function ImportYNAB4({ modalProps }: ImportProps) {const [importing, setImporting] = useState(false);async function onImport() {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({properties: ['openFile'],filters: [{ name: 'ynab', extensions: ['zip'] }],});diff --git a/packages/desktop-client/src/components/manager/ImportYNAB5.tsx b/packages/desktop-client/src/components/manager/ImportYNAB5.tsxindex 0e0a2be5cb..0a775c1fb2 100644--- a/packages/desktop-client/src/components/manager/ImportYNAB5.tsx+++ b/packages/desktop-client/src/components/manager/ImportYNAB5.tsx@@ -33,7 +33,7 @@ export function ImportYNAB5({ modalProps }: ImportProps) {const [importing, setImporting] = useState(false);async function onImport() {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({properties: ['openFile'],filters: [{ name: 'ynab', extensions: ['json'] }],});diff --git a/packages/desktop-client/src/components/manager/ManagementApp.jsx b/packages/desktop-client/src/components/manager/ManagementApp.jsxindex 1bc3f407ef..c5200986f3 100644--- a/packages/desktop-client/src/components/manager/ManagementApp.jsx+++ b/packages/desktop-client/src/components/manager/ManagementApp.jsx@@ -42,7 +42,7 @@ function Version() {},}}>- {`App: v${window.Actual.ACTUAL_VERSION} | Server: ${version}`}+ {`App: v${window.Actual?.ACTUAL_VERSION} | Server: ${version}`}</Text>);}diff --git a/packages/desktop-client/src/components/modals/ImportTransactions.jsx b/packages/desktop-client/src/components/modals/ImportTransactions.jsxindex 3bd05e3008..10e79776dd 100644--- a/packages/desktop-client/src/components/modals/ImportTransactions.jsx+++ b/packages/desktop-client/src/components/modals/ImportTransactions.jsx@@ -849,7 +849,7 @@ export function ImportTransactions({ modalProps, options }) {}async function onNewFile() {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({filters: [{name: 'Financial Files',diff --git a/packages/desktop-client/src/components/settings/Export.tsx b/packages/desktop-client/src/components/settings/Export.tsxindex 824c0f4fa4..790db44dfd 100644--- a/packages/desktop-client/src/components/settings/Export.tsx+++ b/packages/desktop-client/src/components/settings/Export.tsx@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport React, { useState } from 'react';import { format } from 'date-fns';@@ -32,7 +31,7 @@ export function ExportBudget() {return;}- window.Actual.saveFile(+ window.Actual?.saveFile(response.data,`${format(new Date(), 'yyyy-MM-dd')}-${budgetId}.zip`,'Export budget',diff --git a/packages/desktop-client/src/components/settings/FixSplits.tsx b/packages/desktop-client/src/components/settings/FixSplits.tsxindex dab88d8b8b..8a8be2a7fe 100644--- a/packages/desktop-client/src/components/settings/FixSplits.tsx+++ b/packages/desktop-client/src/components/settings/FixSplits.tsx@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport React, { useState } from 'react';import { send } from 'loot-core/src/platform/client/fetch';@@ -54,7 +53,7 @@ function renderResults(results: Results) {export function FixSplits() {const [loading, setLoading] = useState(false);- const [results, setResults] = useState<Results>(null);+ const [results, setResults] = useState<Results | null>(null);async function onFix() {setLoading(true);diff --git a/packages/desktop-client/src/components/settings/Global.tsx b/packages/desktop-client/src/components/settings/Global.tsxindex 92e4ba843a..da9fa01d74 100644--- a/packages/desktop-client/src/components/settings/Global.tsx+++ b/packages/desktop-client/src/components/settings/Global.tsx@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport React, { useState, useEffect, useRef } from 'react';import { useGlobalPref } from '../../hooks/useGlobalPref';@@ -23,7 +22,7 @@ export function GlobalSettings() {}, []);async function onChooseDocumentDir() {- const res = await window.Actual.openFileDialog({+ const res = await window.Actual?.openFileDialog({properties: ['openDirectory'],});if (res) {diff --git a/packages/desktop-client/src/components/settings/Reset.tsx b/packages/desktop-client/src/components/settings/Reset.tsxindex 0e8ea3cea5..78d7f88a9d 100644--- a/packages/desktop-client/src/components/settings/Reset.tsx+++ b/packages/desktop-client/src/components/settings/Reset.tsx@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport React, { useState } from 'react';import { send } from 'loot-core/src/platform/client/fetch';diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsxindex 2f7ef5ada7..800715b117 100644--- a/packages/desktop-client/src/components/settings/index.tsx+++ b/packages/desktop-client/src/components/settings/index.tsx@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport React, { type ReactNode, useEffect } from 'react';import { media } from 'glamor';@@ -58,7 +57,7 @@ function About() {})}`}data-vrt-mask>- <Text>Client version: v{window.Actual.ACTUAL_VERSION}</Text>+ <Text>Client version: v{window.Actual?.ACTUAL_VERSION}</Text><Text>Server version: {version}</Text>{isOutdated ? (<ExternalLink@@ -140,7 +139,7 @@ export function Settings() {<Pagetitle="Settings"style={{- backgroundColor: isNarrowWidth && theme.mobilePageBackground,+ backgroundColor: isNarrowWidth ? theme.mobilePageBackground : undefined,marginInline: floatingSidebar && !isNarrowWidth ? 'auto' : 0,}}>diff --git a/packages/desktop-client/src/gocardless.ts b/packages/desktop-client/src/gocardless.tsindex 809c9f86c6..8277f18dad 100644--- a/packages/desktop-client/src/gocardless.ts+++ b/packages/desktop-client/src/gocardless.ts@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport type { pushModal as pushModalAction } from 'loot-core/src/client/actions/modals';import { send } from 'loot-core/src/platform/client/fetch';import { type GoCardlessToken } from 'loot-core/src/types/models';@@ -24,7 +23,7 @@ function _authorize(if ('error' in resp) return resp;const { link, requisitionId } = resp;- window.Actual.openURLInBrowser(link);+ window.Actual?.openURLInBrowser(link);return send('gocardless-poll-web-token', {upgradingAccountId,diff --git a/packages/desktop-client/src/hooks/useFeatureFlag.ts b/packages/desktop-client/src/hooks/useFeatureFlag.tsindex 5550cfed2c..c3d3fa1376 100644--- a/packages/desktop-client/src/hooks/useFeatureFlag.ts+++ b/packages/desktop-client/src/hooks/useFeatureFlag.ts@@ -1,4 +1,3 @@-// @ts-strict-ignoreimport { useSelector } from 'react-redux';import { type State } from 'loot-core/src/client/state-types';diff --git a/packages/desktop-client/src/plaid.js b/packages/desktop-client/src/plaid.jsindex 7dfd53804b..7f54ca3528 100644--- a/packages/desktop-client/src/plaid.js+++ b/packages/desktop-client/src/plaid.js@@ -10,7 +10,7 @@ function _authorize(pushModal, plaidToken, { onSuccess, onClose }) {if (plaidToken) {url = url + '&plaidToken=' + plaidToken;}- window.Actual.openURLInBrowser(url);+ window.Actual?.openURLInBrowser(url);const { error, data } = await send('poll-web-token', { token });diff --git a/packages/desktop-client/src/tokens.ts b/packages/desktop-client/src/tokens.tsindex f090391c2d..9c5d1facab 100644--- a/packages/desktop-client/src/tokens.ts+++ b/packages/desktop-client/src/tokens.ts@@ -1,4 +1,3 @@-// @ts-strict-ignoreenum BreakpointNames {small = 'small',medium = 'medium',@@ -27,7 +26,10 @@ type BreakpointsPx = {// }export const tokens: BreakpointsPx = Object.entries(breakpoints,-).reduce<BreakpointsPx>((acc, [key, val]) => {- acc[`breakpoint_${key}`] = `${val}px`;- return acc;-}, {} as BreakpointsPx);+).reduce<BreakpointsPx>(+ (acc, [key, val]) => ({+ ...acc,+ [`breakpoint_${key}`]: `${val}px`,+ }),+ {} as BreakpointsPx,+);diff --git a/packages/desktop-client/src/util/versions.ts b/packages/desktop-client/src/util/versions.tsindex 291d236403..09427e15f2 100644--- a/packages/desktop-client/src/util/versions.ts+++ b/packages/desktop-client/src/util/versions.ts@@ -30,7 +30,7 @@ export async function getLatestVersion(): Promise<string | 'unknown'> {const json = await response.json();const tags = json.map(t => t.name)- .concat([`v${window.Actual.ACTUAL_VERSION}`]);+ .concat([`v${window.Actual?.ACTUAL_VERSION}`]);tags.sort(cmpSemanticVersion);return tags[tags.length - 1];@@ -41,7 +41,7 @@ export async function getLatestVersion(): Promise<string | 'unknown'> {}export async function getIsOutdated(latestVersion: string): Promise<boolean> {- const clientVersion = window.Actual.ACTUAL_VERSION;+ const clientVersion = window.Actual?.ACTUAL_VERSION;if (latestVersion === 'unknown') {return Promise.resolve(false);}diff --git a/upcoming-release-notes/2403.md b/upcoming-release-notes/2403.mdnew file mode 100644index 0000000000..9a392343f7--- /dev/null+++ b/upcoming-release-notes/2403.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [MatissJanis]+---++Move some TypeScript files to strict mode