Skip to content

Commit

Permalink
♻️ (typescript) move some files to strict mode (actualbudget#2403)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Mar 3, 2024
1 parent 9fca852 commit b700aee
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 31 deletions.
4 changes: 3 additions & 1 deletion packages/desktop-client/src/components/FatalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/GlobalKeys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { useEffect } from 'react';

import * as Platform from 'loot-core/src/client/platform';
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Version() {
},
}}
>
{`App: v${window.Actual.ACTUAL_VERSION} | Server: ${version}`}
{`App: v${window.Actual?.ACTUAL_VERSION} | Server: ${version}`}
</Text>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/settings/Export.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { useState } from 'react';

import { format } from 'date-fns';
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { useState } from 'react';

import { send } from 'loot-core/src/platform/client/fetch';
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/settings/Global.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { useState, useEffect, useRef } from 'react';

import { useGlobalPref } from '../../hooks/useGlobalPref';
Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion packages/desktop-client/src/components/settings/Reset.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { useState } from 'react';

import { send } from 'loot-core/src/platform/client/fetch';
Expand Down
5 changes: 2 additions & 3 deletions packages/desktop-client/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { type ReactNode, useEffect } from 'react';

import { media } from 'glamor';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,7 +139,7 @@ export function Settings() {
<Page
title="Settings"
style={{
backgroundColor: isNarrowWidth && theme.mobilePageBackground,
backgroundColor: isNarrowWidth ? theme.mobilePageBackground : undefined,
marginInline: floatingSidebar && !isNarrowWidth ? 'auto' : 0,
}}
>
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/gocardless.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/desktop-client/src/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { useSelector } from 'react-redux';

import { type State } from 'loot-core/src/client/state-types';
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/plaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
12 changes: 7 additions & 5 deletions packages/desktop-client/src/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
enum BreakpointNames {
small = 'small',
medium = 'medium',
Expand Down Expand Up @@ -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,
);
4 changes: 2 additions & 2 deletions packages/desktop-client/src/util/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2403.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

Move some TypeScript files to strict mode

0 comments on commit b700aee

Please sign in to comment.