Skip to content
Snippets Groups Projects
Unverified Commit 66bfef28 authored by Tom French's avatar Tom French Committed by GitHub
Browse files

chore: migrate some JS to TS (#1078)

parent f03b8a3a
No related branches found
No related tags found
No related merge requests found
......@@ -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 () => {
......
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 => {
......
......@@ -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);
......
......@@ -62,6 +62,17 @@ const boundActions = bindActionCreators(actions, store.dispatch);
// Listen for global events from the server or main process
handleGlobalEvents(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 it
window.__actionsForMenu = boundActions;
......
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;
......
export function getModalRoute(name) {
export function getModalRoute(name: string): [string, string] {
let parts = name.split('/');
return [parts[0], parts.slice(1).join('/')];
}
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;
}
---
category: Maintenance
authors: [TomAFrench]
---
Migrate some files in `desktop-client` to use Typescript.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment