From 7fdbef75738f98db9e5a00a2bc0dfef799a11030 Mon Sep 17 00:00:00 2001 From: Linus Miller Date: Sat, 13 Dec 2025 19:25:23 +0100 Subject: [PATCH] fix types --- bin/add_fisken_invoices.ts | 4 +- client/public/components/accounts_page.tsx | 13 ++- client/public/components/app.tsx | 13 ++- client/public/components/balances_page.tsx | 10 ++- client/public/components/entries_page.tsx | 24 +++--- client/public/components/entry_page.tsx | 12 ++- client/public/components/error_page.tsx | 4 +- client/public/components/footer.tsx | 4 +- client/public/components/head.ts | 35 ++++---- client/public/components/header.tsx | 6 +- client/public/components/invoice.tsx | 4 +- client/public/components/invoice_page.tsx | 10 ++- .../components/invoices_by_supplier_page.tsx | 20 ++--- client/public/components/invoices_page.tsx | 10 ++- client/public/components/not_found_page.tsx | 6 +- client/public/components/object.tsx | 4 +- client/public/components/objects_page.tsx | 11 +-- client/public/components/results_page.tsx | 12 +-- client/public/components/start_page.tsx | 4 +- .../public/components/transactions_page.tsx | 16 ++-- client/public/utils/format_number.ts | 4 +- client/shared/components/button_factory.tsx | 59 +++++++++---- client/shared/components/checkbox_factory.tsx | 52 ++++++------ .../components/image_upload_factory.tsx | 47 +++++++--- client/shared/components/input_factory.tsx | 45 ++++++---- .../shared/components/link_button_factory.tsx | 57 +++++++++---- client/shared/components/portal.tsx | 7 +- client/shared/components/select_factory.tsx | 52 ++++++++---- client/shared/components/textarea_factory.tsx | 36 ++++---- client/shared/hooks/use_request_state.ts | 11 ++- client/shared/utils/disable_scroll.ts | 4 +- client/shared/utils/escape_regex.ts | 2 +- client/shared/utils/is_loading.ts | 2 +- client/shared/utils/merge_styles.ts | 2 +- client/shared/utils/serialize_form.ts | 2 +- client/shared/utils/throttle.ts | 6 +- client/test/jsdom_polyfills.ts | 2 + package.json | 1 + pnpm-lock.yaml | 8 ++ server/env.ts | 36 ++++---- server/handlers/error.ts | 12 ++- server/handlers/robots.ts | 7 +- server/lib/console.ts | 1 + server/lib/html.ts | 21 ++--- server/lib/knex.ts | 6 +- server/lib/parse_line.test.ts | 11 ++- server/lib/parse_line.ts | 55 +++++++++--- server/lib/parse_stream.ts | 22 ++--- server/lib/pino_transport_console.ts | 51 ++++++++--- server/lib/split.ts | 8 +- server/plugins/vite.ts | 30 +------ server/plugins/vite/development.ts | 45 +++++----- server/plugins/vite/production.ts | 80 ++++++++++------- server/plugins/vite/types.ts | 56 ++++++++++++ server/templates/public.ts | 17 +++- server/types.ts | 10 +++ shared/global.d.ts | 2 +- shared/types.ts | 85 +++++++++++++++++-- tsconfig.json | 1 + 59 files changed, 779 insertions(+), 398 deletions(-) create mode 100644 server/plugins/vite/types.ts create mode 100644 server/types.ts diff --git a/bin/add_fisken_invoices.ts b/bin/add_fisken_invoices.ts index 97d3fae..328456f 100644 --- a/bin/add_fisken_invoices.ts +++ b/bin/add_fisken_invoices.ts @@ -16,8 +16,8 @@ knex.destroy() async function readdir(dir: string) { const files = (await fs.readdir(dir)).toSorted((a: string, b: string) => { - const [, aNum] = a.match(rFileName) - const [, bNum] = b.match(rFileName) + const [, aNum] = a.match(rFileName) as string[] + const [, bNum] = b.match(rFileName) as string[] if (parseInt(aNum) > parseInt(bNum)) { return 1 diff --git a/client/public/components/accounts_page.tsx b/client/public/components/accounts_page.tsx index 4709118..59211db 100644 --- a/client/public/components/accounts_page.tsx +++ b/client/public/components/accounts_page.tsx @@ -1,16 +1,15 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import { useEffect, useState } from 'preact/hooks' import rek from 'rek' import Head from './head.ts' -// import s from './accounts_page.module.scss' -const AccountsPage = () => { - const [accounts, setAccounts] = useState([]) +import type { Account } from '../../../shared/types.ts' + +const AccountsPage: FunctionComponent = () => { + const [accounts, setAccounts] = useState([]) useEffect(() => { - rek('/api/accounts').then((accounts) => { - setAccounts(accounts) - }) + rek('/api/accounts').then(setAccounts) }, []) return ( diff --git a/client/public/components/app.tsx b/client/public/components/app.tsx index 0045c47..f383054 100644 --- a/client/public/components/app.tsx +++ b/client/public/components/app.tsx @@ -1,4 +1,4 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import { useCallback, useEffect } from 'preact/hooks' import { LocationProvider, Route, Router } from 'preact-iso' import { get } from 'lowline' @@ -11,6 +11,11 @@ import throttle from '../../shared/utils/throttle.ts' import s from './app.module.scss' +type Props = { + error?: Error + title?: string +} + const remember = throttle(function remember() { window.history.replaceState( { @@ -22,7 +27,7 @@ const remember = throttle(function remember() { ) }, 100) -export default function App({ error, title }) { +const App: FunctionComponent = ({ error, title }) => { useEffect(() => { addEventListener('scroll', remember) @@ -52,7 +57,7 @@ export default function App({ error, title }) { ) : ( {routes.map((route) => ( - + ))} )} @@ -63,3 +68,5 @@ export default function App({ error, title }) { ) } + +export default App diff --git a/client/public/components/balances_page.tsx b/client/public/components/balances_page.tsx index 3c956a9..1e9c39d 100644 --- a/client/public/components/balances_page.tsx +++ b/client/public/components/balances_page.tsx @@ -1,4 +1,4 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import { useEffect, useState } from 'preact/hooks' import cn from 'classnames' import rek from 'rek' @@ -6,13 +6,15 @@ import Head from './head.ts' import { formatNumber } from '../utils/format_number.ts' import s from './balances_page.module.scss' -const BalancesPage = () => { - const [balances, setBalances] = useState([]) +import type { Balance, FinancialYear } from '../../../shared/types.ts' + +const BalancesPage: FunctionComponent = () => { + const [balances, setBalances] = useState([]) const [years, setYears] = useState([]) useEffect(() => { rek(`/api/balances`).then(setBalances) - rek(`/api/financial-years`).then((years) => setYears(years.map((fy) => fy.year))) + rek(`/api/financial-years`).then((financialYears: FinancialYear[]) => setYears(financialYears.map((fy) => fy.year))) }, []) return ( diff --git a/client/public/components/entries_page.tsx b/client/public/components/entries_page.tsx index f0e0698..f20127b 100644 --- a/client/public/components/entries_page.tsx +++ b/client/public/components/entries_page.tsx @@ -1,4 +1,4 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import { useCallback, useEffect, useState } from 'preact/hooks' import { useLocation } from 'preact-iso' import { isEmpty } from 'lowline' @@ -8,12 +8,14 @@ import rek from 'rek' import Head from './head.ts' import serializeForm from '../../shared/utils/serialize_form.ts' +import type { Entry, FinancialYear, Journal } from '../../../shared/types.ts' + const dateYear = new Date().getFullYear() -const EntriesPage = () => { - const [journals, setJournals] = useState([]) - const [financialYears, setFinancialYears] = useState([]) - const [entries, setEntries] = useState([]) +const EntriesPage: FunctionComponent = () => { + const [journals, setJournals] = useState([]) + const [financialYears, setFinancialYears] = useState([]) + const [entries, setEntries] = useState([]) const location = useLocation() @@ -22,7 +24,7 @@ const EntriesPage = () => { const onSubmit = useCallback((e: SubmitEvent) => { e.preventDefault() - const values = serializeForm(e.target as HTMLFormElement) + const values = serializeForm(e.target as HTMLFormElement) as Record const search = !isEmpty(values) ? '?' + qs.stringify(values) : '' @@ -30,16 +32,12 @@ const EntriesPage = () => { }, []) useEffect(() => { - rek('/api/journals').then((journals) => { - setJournals(journals) - }) - rek('/api/financial-years').then((financialYears) => { - setFinancialYears(financialYears) - }) + rek('/api/journals').then(setJournals) + rek('/api/financial-years').then(setFinancialYears) }, []) useEffect(() => { - rek(`/api/entries?journal=${selectedJournal}&year=${selectedYear}`).then((entries) => setEntries(entries)) + rek(`/api/entries?journal=${selectedJournal}&year=${selectedYear}`).then(setEntries) }, [selectedJournal, selectedYear]) return financialYears.length && journals.length ? ( diff --git a/client/public/components/entry_page.tsx b/client/public/components/entry_page.tsx index 4b0b2ac..7ff51e0 100644 --- a/client/public/components/entry_page.tsx +++ b/client/public/components/entry_page.tsx @@ -1,4 +1,4 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import { useEffect, useState } from 'preact/hooks' import { useRoute } from 'preact-iso' import { formatNumber } from '../utils/format_number.ts' @@ -8,14 +8,12 @@ import { type Entry } from '../../../shared/types.ts' import Head from './head.ts' -const EntriesPage = () => { - const [entry, setEntry] = useState(null) +const EntryPage: FunctionComponent = () => { + const [entry, setEntry] = useState(null) const route = useRoute() useEffect(() => { - rek(`/api/entries/${route.params.id}`).then((entry) => { - setEntry(entry) - }) + rek(`/api/entries/${route.params.id}`).then(setEntry) }, []) if (!entry) return @@ -84,4 +82,4 @@ const EntriesPage = () => { ) } -export default EntriesPage +export default EntryPage diff --git a/client/public/components/error_page.tsx b/client/public/components/error_page.tsx index 35764e1..6ffd2cc 100644 --- a/client/public/components/error_page.tsx +++ b/client/public/components/error_page.tsx @@ -1,7 +1,7 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' import Head from './head.ts' -const OtherPage = ({ error }) => ( +const OtherPage: FunctionComponent<{ error: Error }> = ({ error }) => (
: Error diff --git a/client/public/components/footer.tsx b/client/public/components/footer.tsx index 861be7c..5eab7f4 100644 --- a/client/public/components/footer.tsx +++ b/client/public/components/footer.tsx @@ -1,5 +1,5 @@ -import { h } from 'preact' +import { h, type FunctionComponent } from 'preact' -const Footer = () =>