A local-first personal finance app
:recycle: (TypeScript) fix strictFunctionTypes violations (pt 5) (#2072)
Matiss Janis Aboltins7a40a645e6e2
diff --git a/packages/desktop-client/src/components/autocomplete/SavedFilterAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/SavedFilterAutocomplete.tsxindex 989e0b1712..684cdbb54f 100644--- a/packages/desktop-client/src/components/autocomplete/SavedFilterAutocomplete.tsx+++ b/packages/desktop-client/src/components/autocomplete/SavedFilterAutocomplete.tsx@@ -74,7 +74,6 @@ export default function SavedFilterAutocomplete({suggestions={filters}renderItems={(items, getItemProps, highlightedIndex) => (<FilterList- // @ts-expect-error This issue will go away when `strictFunctionTypes` is enableditems={items}getItemProps={getItemProps}highlightedIndex={highlightedIndex}diff --git a/packages/desktop-client/src/hooks/useActions.ts b/packages/desktop-client/src/hooks/useActions.tsindex 07db4684f0..2952eaf8a0 100644--- a/packages/desktop-client/src/hooks/useActions.ts+++ b/packages/desktop-client/src/hooks/useActions.ts@@ -15,10 +15,15 @@ type ActionReturnType<T extends (...args: unknown[]) => unknown> =export type BoundActions = {[Key in keyof typeof actions]: (...args: Parameters<(typeof actions)[Key]>- ) => ActionReturnType<(typeof actions)[Key]>;+ ) => // @ts-expect-error temporarily disabling this TS error; eventually the `useActions` hook should be removed+ ActionReturnType<(typeof actions)[Key]>;};// https://react-redux.js.org/api/hooks#recipe-useactions+/**+ * @deprecated please use actions directly with `useDispatch`+ * @see https://github.com/reduxjs/react-redux/issues/1252#issuecomment-488160930+ **/export function useActions() {const dispatch = useDispatch();return useMemo(() => {diff --git a/packages/loot-core/src/platform/server/sqlite/index.electron.ts b/packages/loot-core/src/platform/server/sqlite/index.electron.tsindex 146e8ac192..0374f34d8b 100644--- a/packages/loot-core/src/platform/server/sqlite/index.electron.ts+++ b/packages/loot-core/src/platform/server/sqlite/index.electron.ts@@ -98,9 +98,11 @@ export function openDatabase(pathOrBuffer: string | Buffer) {const db = new SQL(pathOrBuffer);// Define Unicode-aware LOWER and UPPER implementation.// This is necessary because better-sqlite3 uses SQLite build without ICU support.+ // @ts-expect-error @types/better-sqlite3 does not support setting strict 3rd argumentdb.function('UNICODE_LOWER', { deterministic: true }, (arg: string | null) =>arg?.toLowerCase(),);+ // @ts-expect-error @types/better-sqlite3 does not support setting strict 3rd argumentdb.function('UNICODE_UPPER', { deterministic: true }, (arg: string | null) =>arg?.toUpperCase(),);diff --git a/packages/loot-core/src/server/aql/compiler.ts b/packages/loot-core/src/server/aql/compiler.tsindex ade3d1d020..29b437ec38 100644--- a/packages/loot-core/src/server/aql/compiler.ts+++ b/packages/loot-core/src/server/aql/compiler.ts@@ -989,10 +989,21 @@ export function isAggregateQuery(queryState) {});}-type SchemaConfig = {- tableViews?: Record<string, unknown> | ((...args: unknown[]) => unknown);+export type SchemaConfig = {+ tableViews?:+ | Record<string, unknown>+ | ((name: string, config: { withDead; isJoin; tableOptions }) => unknown);tableFilters?: (name: string) => unknown[];- customizeQuery?: <T>(queryString: T) => T;+ customizeQuery?: <T extends { table: string; orderExpressions: unknown[] }>(+ queryString: T,+ ) => T;+ views?: Record<+ string,+ {+ fields?: Record<string, string>;+ [key: `v_${string}`]: string | ((internalFields, publicFields) => string);+ }+ >;};export function compileQuery(queryState,diff --git a/packages/loot-core/src/server/aql/schema/index.ts b/packages/loot-core/src/server/aql/schema/index.tsindex 26af5205b0..1af6735bdc 100644--- a/packages/loot-core/src/server/aql/schema/index.ts+++ b/packages/loot-core/src/server/aql/schema/index.ts@@ -1,3 +1,5 @@+import { SchemaConfig } from '../compiler';+function f(type: string, opts?: Record<string, unknown>) {return { type, ...opts };}@@ -140,7 +142,7 @@ export const schema = {},};-export const schemaConfig = {+export const schemaConfig: SchemaConfig = {// Note: these views *must* represent the underlying table that we// are mapping here. The compiler makes optimizations with this// assumptiondiff --git a/packages/loot-core/src/server/sync/sync.property.test.ts b/packages/loot-core/src/server/sync/sync.property.test.tsindex d748f9d516..cbe5cefe01 100644--- a/packages/loot-core/src/server/sync/sync.property.test.ts+++ b/packages/loot-core/src/server/sync/sync.property.test.ts@@ -93,7 +93,8 @@ const baseTime = 1565374471903;const clientId1 = '80dd7da215247293';const clientId2 = '90xU1sd5124329ac';-function makeGen<T extends Arbitrary<unknown>>({+// eslint-disable-next-line @typescript-eslint/no-explicit-any+function makeGen<T extends Arbitrary<any>>({table,row,field,diff --git a/tsconfig.json b/tsconfig.jsonindex 844bcaf11c..a426766d86 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -15,8 +15,7 @@"downlevelIteration": true,// TODO: enable once every file is ts// "strict": true,- // TODO: enable once the violations are fixed- // "strictFunctionTypes": true,+ "strictFunctionTypes": true,"noFallthroughCasesInSwitch": true,"skipLibCheck": true,"jsx": "preserve",diff --git a/upcoming-release-notes/2072.md b/upcoming-release-notes/2072.mdnew file mode 100644index 0000000000..edad616bb1--- /dev/null+++ b/upcoming-release-notes/2072.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [MatissJanis]+---++Fixing TypeScript issues when enabling `strictFunctionTypes` (pt.5).