Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ (TypeScript) fix strictFunctionTypes violations (pt 5) #2072

Merged
merged 13 commits into from
Jan 6, 2024
Merged
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: 2 additions & 1 deletion packages/loot-core/src/server/sync/sync.property.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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).
Loading