From b700aee87de10a50f7bed93cfc9d3f34096a6b89 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Sun, 3 Mar 2024 17:50:13 +0000 Subject: [PATCH] :recycle: (typescript) move some files to strict mode (#2403) --- .../desktop-client/src/components/FatalError.tsx | 4 +++- packages/desktop-client/src/components/GlobalKeys.ts | 3 +-- .../src/components/accounts/Account.jsx | 4 ++-- .../src/components/manager/ImportActual.tsx | 2 +- .../src/components/manager/ImportYNAB4.tsx | 2 +- .../src/components/manager/ImportYNAB5.tsx | 2 +- .../src/components/manager/ManagementApp.jsx | 2 +- .../src/components/modals/ImportTransactions.jsx | 2 +- .../src/components/settings/Export.tsx | 3 +-- .../src/components/settings/FixSplits.tsx | 3 +-- .../src/components/settings/Global.tsx | 3 +-- .../desktop-client/src/components/settings/Reset.tsx | 1 - .../desktop-client/src/components/settings/index.tsx | 5 ++--- packages/desktop-client/src/gocardless.ts | 3 +-- packages/desktop-client/src/hooks/useFeatureFlag.ts | 1 - packages/desktop-client/src/plaid.js | 2 +- packages/desktop-client/src/tokens.ts | 12 +++++++----- packages/desktop-client/src/util/versions.ts | 4 ++-- upcoming-release-notes/2403.md | 6 ++++++ 19 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 upcoming-release-notes/2403.md diff --git a/packages/desktop-client/src/components/FatalError.tsx b/packages/desktop-client/src/components/FatalError.tsx index ebed6c72ee6..9b96ba0fe5c 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 ? : } - + setShowError(true)}>Show Error diff --git a/packages/desktop-client/src/components/GlobalKeys.ts b/packages/desktop-client/src/components/GlobalKeys.ts index 1109e4250cb..a6e785347f2 100644 --- a/packages/desktop-client/src/components/GlobalKeys.ts +++ b/packages/desktop-client/src/components/GlobalKeys.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { 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.jsx index 48f30a99a44..18a560f9979 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.tsx index 665c4ea8ff3..a6863deb536 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.tsx index f95de762c22..338a5dd5e27 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.tsx index 0e0a2be5cb3..0a775c1fb2f 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.jsx index 1bc3f407eff..c5200986f3a 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}`} ); } diff --git a/packages/desktop-client/src/components/modals/ImportTransactions.jsx b/packages/desktop-client/src/components/modals/ImportTransactions.jsx index 3bd05e3008c..10e79776dd3 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.tsx index 824c0f4fa41..790db44dfd7 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-ignore import 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.tsx index dab88d8b8b1..8a8be2a7feb 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-ignore import 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(null); + const [results, setResults] = useState(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.tsx index 92e4ba843a8..da9fa01d744 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-ignore import 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.tsx index 0e8ea3cea5a..78d7f88a9dc 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-ignore import 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.tsx index 2f7ef5ada70..800715b1179 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-ignore import React, { type ReactNode, useEffect } from 'react'; import { media } from 'glamor'; @@ -58,7 +57,7 @@ function About() { })}`} data-vrt-mask > - Client version: v{window.Actual.ACTUAL_VERSION} + Client version: v{window.Actual?.ACTUAL_VERSION} Server version: {version} {isOutdated ? ( diff --git a/packages/desktop-client/src/gocardless.ts b/packages/desktop-client/src/gocardless.ts index 809c9f86c6e..8277f18dada 100644 --- a/packages/desktop-client/src/gocardless.ts +++ b/packages/desktop-client/src/gocardless.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import 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.ts index 5550cfed2cd..c3d3fa1376f 100644 --- a/packages/desktop-client/src/hooks/useFeatureFlag.ts +++ b/packages/desktop-client/src/hooks/useFeatureFlag.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { 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.js index 7dfd53804b5..7f54ca35280 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.ts index f090391c2d3..9c5d1facabe 100644 --- a/packages/desktop-client/src/tokens.ts +++ b/packages/desktop-client/src/tokens.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore enum BreakpointNames { small = 'small', medium = 'medium', @@ -27,7 +26,10 @@ type BreakpointsPx = { // } export const tokens: BreakpointsPx = Object.entries( breakpoints, -).reduce((acc, [key, val]) => { - acc[`breakpoint_${key}`] = `${val}px`; - return acc; -}, {} as BreakpointsPx); +).reduce( + (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.ts index 291d236403f..09427e15f2c 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 { 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 { } export async function getIsOutdated(latestVersion: string): Promise { - 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.md new file mode 100644 index 00000000000..9a392343f7b --- /dev/null +++ b/upcoming-release-notes/2403.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MatissJanis] +--- + +Move some TypeScript files to strict mode