A local-first personal finance app
chore: migrate some JS to TS (#1078)
Tom French66bfef28c0d8
diff --git a/packages/desktop-client/src/hooks/useLatestVersion.js b/packages/desktop-client/src/hooks/useLatestVersion.tssimilarity index 89%rename from packages/desktop-client/src/hooks/useLatestVersion.jsrename to packages/desktop-client/src/hooks/useLatestVersion.tsindex 436392b809..2a29a73fa9 100644--- a/packages/desktop-client/src/hooks/useLatestVersion.js+++ b/packages/desktop-client/src/hooks/useLatestVersion.ts@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';import { getIsOutdated, getLatestVersion } from '../util/versions';-function useIsOutdated() {+function useIsOutdated(): boolean {let [isOutdated, setIsOutdated] = useState(false);const latestVersion = useLatestVersion();@@ -15,7 +15,7 @@ function useIsOutdated() {return isOutdated;}-function useLatestVersion() {+function useLatestVersion(): string {let [latestVersion, setLatestVersion] = useState('');useEffect(() => {(async () => {diff --git a/packages/desktop-client/src/hooks/useResizeObserver.js b/packages/desktop-client/src/hooks/useResizeObserver.tssimilarity index 75%rename from packages/desktop-client/src/hooks/useResizeObserver.jsrename to packages/desktop-client/src/hooks/useResizeObserver.tsindex fa1abbe48f..49a0a24d5d 100644--- a/packages/desktop-client/src/hooks/useResizeObserver.js+++ b/packages/desktop-client/src/hooks/useResizeObserver.ts@@ -1,6 +1,8 @@import { useRef, useCallback } from 'react';-export default function useResizeObserver(func) {+export default function useResizeObserver(+ func: (contentRect: DOMRectReadOnly) => ResizeObserver,+): (el: unknown) => void {let observer = useRef(null);if (!observer.current) {observer.current = new ResizeObserver(entries => {diff --git a/packages/desktop-client/src/hooks/useSyncServerStatus.js b/packages/desktop-client/src/hooks/useSyncServerStatus.tssimilarity index 71%rename from packages/desktop-client/src/hooks/useSyncServerStatus.jsrename to packages/desktop-client/src/hooks/useSyncServerStatus.tsindex 54d989ce88..114e58f2f4 100644--- a/packages/desktop-client/src/hooks/useSyncServerStatus.js+++ b/packages/desktop-client/src/hooks/useSyncServerStatus.ts@@ -2,7 +2,9 @@ import { useSelector } from 'react-redux';import { useServerURL } from '../components/ServerContext';-export default function useSyncServerStatus() {+type SyncServerStatus = 'offline' | 'no-server' | 'online';++export default function useSyncServerStatus(): SyncServerStatus {const serverUrl = useServerURL();const userData = useSelector(state => state.user.data);diff --git a/packages/desktop-client/src/index.js b/packages/desktop-client/src/index.tsxsimilarity index 91%rename from packages/desktop-client/src/index.jsrename to packages/desktop-client/src/index.tsxindex 8c9e9d9369..30cd6247ac 100644--- a/packages/desktop-client/src/index.js+++ b/packages/desktop-client/src/index.tsx@@ -62,6 +62,17 @@ const boundActions = bindActionCreators(actions, store.dispatch);// Listen for global events from the server or main processhandleGlobalEvents(boundActions, store);+declare global {+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions+ interface Window {+ __actionsForMenu: typeof actions;++ $send: typeof send;+ $query: typeof runQuery;+ $q: typeof q;+ }+}+// Expose this to the main process to menu items can access itwindow.__actionsForMenu = boundActions;diff --git a/packages/desktop-client/src/polyfills.js b/packages/desktop-client/src/polyfills.tssimilarity index 71%rename from packages/desktop-client/src/polyfills.jsrename to packages/desktop-client/src/polyfills.tsindex 851cd01959..0b58bbcbff 100644--- a/packages/desktop-client/src/polyfills.js+++ b/packages/desktop-client/src/polyfills.ts@@ -1,4 +1,4 @@-export default async function installPolyfills() {+export default async function installPolyfills(): Promise<void> {if ('ResizeObserver' in window === false) {const module = await import('@juggle/resize-observer');window.ResizeObserver = module.ResizeObserver;diff --git a/packages/desktop-client/src/util.js b/packages/desktop-client/src/util.tssimilarity index 55%rename from packages/desktop-client/src/util.jsrename to packages/desktop-client/src/util.tsindex 35e1fadd11..e506321203 100644--- a/packages/desktop-client/src/util.js+++ b/packages/desktop-client/src/util.ts@@ -1,4 +1,4 @@-export function getModalRoute(name) {+export function getModalRoute(name: string): [string, string] {let parts = name.split('/');return [parts[0], parts.slice(1).join('/')];}diff --git a/packages/desktop-client/src/util/versions.js b/packages/desktop-client/src/util/versions.tssimilarity index 67%rename from packages/desktop-client/src/util/versions.jsrename to packages/desktop-client/src/util/versions.tsindex 46406bc7f0..c87e00b2ba 100644--- a/packages/desktop-client/src/util/versions.js+++ b/packages/desktop-client/src/util/versions.ts@@ -1,18 +1,21 @@-function parseSemanticVersion(versionString) {+function parseSemanticVersion(versionString): [number, number, number] {return versionString.replace('v', '').split('.').map(n => parseInt(n));}-export function cmpSemanticVersion(versionStringA, versionStringB) {+export function cmpSemanticVersion(+ versionStringA: string,+ versionStringB: string,+): number {let x = parseSemanticVersion(versionStringA);let y = parseSemanticVersion(versionStringB);return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];}-export async function getLatestVersion() {+export async function getLatestVersion(): Promise<string> {let response = await fetch('https://api.github.com/repos/actualbudget/actual/tags',);@@ -23,7 +26,7 @@ export async function getLatestVersion() {return tags[tags.length - 1];}-export async function getIsOutdated(latestVersion) {+export async function getIsOutdated(latestVersion: string): Promise<boolean> {let clientVersion = window.Actual.ACTUAL_VERSION;return cmpSemanticVersion(clientVersion, latestVersion) < 0;}diff --git a/upcoming-release-notes/1078.md b/upcoming-release-notes/1078.mdnew file mode 100644index 0000000000..7acea615da--- /dev/null+++ b/upcoming-release-notes/1078.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [TomAFrench]+---++Migrate some files in `desktop-client` to use Typescript.\ No newline at end of file