Skip to content

Commit

Permalink
♻️ (TypeScript) fix strictFunctionTypes violations (pt 5)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis committed Dec 12, 2023
1 parent 6b4de0f commit dcdf461
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 enabled
items={items}
getItemProps={getItemProps}
highlightedIndex={highlightedIndex}
Expand Down
7 changes: 6 additions & 1 deletion packages/desktop-client/src/hooks/useActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 argument
db.function('UNICODE_LOWER', { deterministic: true }, (arg: string | null) =>
arg?.toLowerCase(),
);
// @ts-expect-error @types/better-sqlite3 does not support setting strict 3rd argument
db.function('UNICODE_UPPER', { deterministic: true }, (arg: string | null) =>
arg?.toUpperCase(),
);
Expand Down
17 changes: 14 additions & 3 deletions packages/loot-core/src/server/aql/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion packages/loot-core/src/server/aql/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SchemaConfig } from '../compiler';

function f(type: string, opts?: Record<string, unknown>) {
return { type, ...opts };
}
Expand Down Expand Up @@ -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
// assumption
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2072.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

Fixing TypeScript issues when enabling `strictFunctionTypes` (pt.5).

0 comments on commit dcdf461

Please sign in to comment.