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

🏷️ making some files comply with strict TS #2247

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/desktop-client/src/components/UpdateNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React from 'react';
import { useSelector } from 'react-redux';

Expand All @@ -11,14 +10,6 @@ import { LinkButton } from './common/LinkButton';
import { Text } from './common/Text';
import { View } from './common/View';

function closeNotification(setAppState) {
// Set a flag to never show an update notification again for this session
setAppState({
updateInfo: null,
showUpdateNotification: false,
});
}

export function UpdateNotification() {
const updateInfo = useSelector(state => state.app.updateInfo);
const showUpdateNotification = useSelector(
Expand Down Expand Up @@ -68,7 +59,7 @@ export function UpdateNotification() {
textDecoration: 'underline',
}}
onClick={() =>
window.Actual.openURLInBrowser(
window.Actual?.openURLInBrowser(
'https://actualbudget.org/docs/releases',
)
}
Expand All @@ -80,7 +71,13 @@ export function UpdateNotification() {
type="bare"
aria-label="Close"
style={{ display: 'inline', padding: '1px 7px 2px 7px' }}
onClick={() => closeNotification(setAppState)}
onClick={() => {
// Set a flag to never show an update notification again for this session
setAppState({
updateInfo: null,
showUpdateNotification: false,
});
}}
>
<SvgClose
width={9}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,26 +691,28 @@ function MultiAutocomplete<T extends Item>({

type AutocompleteFooterProps = {
show?: boolean;
embedded: boolean;
embedded?: boolean;
children: ReactNode;
};
export function AutocompleteFooter({
show = true,
embedded,
children,
}: AutocompleteFooterProps) {
if (!show) {
return null;
}

return (
show && (
<View
style={{
flexShrink: 0,
...(embedded ? { paddingTop: 5 } : { padding: 5 }),
}}
onMouseDown={e => e.preventDefault()}
>
{children}
</View>
)
<View
style={{
flexShrink: 0,
...(embedded ? { paddingTop: 5 } : { padding: 5 }),
}}
onMouseDown={e => e.preventDefault()}
>
{children}
</View>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, {
type ComponentProps,
Fragment,
Expand All @@ -25,9 +24,11 @@ import { Autocomplete, defaultFilterSuggestion } from './Autocomplete';

export type CategoryListProps = {
items: Array<CategoryEntity & { group?: CategoryGroupEntity }>;
getItemProps?: (arg: { item }) => Partial<ComponentProps<typeof View>>;
getItemProps?: (arg: {
item: CategoryEntity;
}) => Partial<ComponentProps<typeof View>>;
highlightedIndex: number;
embedded: boolean;
embedded?: boolean;
footer?: ReactNode;
renderSplitTransactionButton?: (
props: SplitTransactionButtonProps,
Expand All @@ -47,7 +48,7 @@ function CategoryList({
renderCategoryItemGroupHeader = defaultRenderCategoryItemGroupHeader,
renderCategoryItem = defaultRenderCategoryItem,
}: CategoryListProps) {
let lastGroup = null;
let lastGroup: string | undefined | null = null;

return (
<View>
Expand All @@ -72,10 +73,10 @@ function CategoryList({
lastGroup = item.cat_group;
return (
<Fragment key={item.id}>
{showGroup && (
<Fragment key={item.group?.name}>
{showGroup && item.group?.name && (
<Fragment key={item.group.name}>
{renderCategoryItemGroupHeader({
title: item.group?.name,
title: item.group.name,
})}
</Fragment>
)}
Expand Down Expand Up @@ -125,7 +126,7 @@ export function CategoryAutocomplete({
categoryGroups.reduce(
(list, group) =>
list.concat(
group.categories
(group.categories || [])
.filter(category => category.cat_group === group.id)
.map(category => ({
...category,
Expand Down Expand Up @@ -214,8 +215,7 @@ type SplitTransactionButtonProps = {
style?: CSSProperties;
};

// eslint-disable-next-line import/no-unused-modules
export function SplitTransactionButton({
function SplitTransactionButton({
Icon,
highlighted,
embedded,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-strict-ignore
import { APIError } from '../../../server/errors';
import { runHandler, isMutating } from '../../../server/mutators';
import { captureException } from '../../exceptions';

Expand Down Expand Up @@ -70,7 +71,7 @@ export const init: T.Init = function (_socketName, handlers) {
type: 'reply',
id,
result: null,
error: { type: 'APIError', message: 'Unknown method: ' + name },
error: APIError('Unknown method: ' + name),
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-strict-ignore
import { APIError } from '../../../server/errors';
import { runHandler, isMutating } from '../../../server/mutators';
import { captureException } from '../../exceptions';

Expand Down Expand Up @@ -90,7 +91,7 @@ export const init: T.Init = function (serverChn, handlers) {
type: 'reply',
id,
result: null,
error: { type: 'APIError', message: 'Unknown method: ' + name },
error: APIError('Unknown method: ' + name),
});
}
},
Expand Down
6 changes: 1 addition & 5 deletions packages/loot-core/src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ import {
import { runQuery as aqlQuery } from './aql';
import * as cloudStorage from './cloud-storage';
import * as db from './db';
import { APIError } from './errors';
import { runMutator } from './mutators';
import * as prefs from './prefs';
import * as sheet from './sheet';
import { setSyncingMode, batchMessages } from './sync';

let IMPORT_MODE = false;

// This is duplicate from main.js...
function APIError(msg, meta?) {
return { type: 'APIError', message: msg, meta };
}

// The API is different in two ways: we never want undo enabled, and
// we also need to notify the UI manually if stuff has changed (if
// they are connecting to an already running instance, the UI should
Expand Down
10 changes: 6 additions & 4 deletions packages/loot-core/src/server/db/sort.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-strict-ignore
export const SORT_INCREMENT = 16384;

function midpoint(items, to) {
function midpoint<T extends { sort_order: number }>(items: T[], to: number) {
const below = items[to - 1];
const above = items[to];

Expand All @@ -14,11 +13,14 @@ function midpoint(items, to) {
}
}

export function shoveSortOrders(items, targetId?: string) {
export function shoveSortOrders<T extends { id: string; sort_order: number }>(
items: T[],
targetId?: string,
) {
const to = items.findIndex(item => item.id === targetId);
const target = items[to];
const before = items[to - 1];
const updates = [];
const updates: Array<{ id: string; sort_order: number }> = [];

// If no target is specified, append at the end
if (!targetId || to === -1) {
Expand Down
52 changes: 37 additions & 15 deletions packages/loot-core/src/server/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-strict-ignore
// TODO: normalize error types
export class PostError extends Error {
meta;
reason;
type;
meta?: { meta: string };
reason: string;
type: 'PostError';

constructor(reason, meta?) {
constructor(reason: string, meta?: { meta: string }) {
super('PostError: ' + reason);
this.type = 'PostError';
this.reason = reason;
Expand All @@ -14,21 +13,38 @@ export class PostError extends Error {
}

export class HTTPError extends Error {
statusCode;
responseBody;
statusCode: number;
responseBody: string;

constructor(code, body) {
constructor(code: number, body: string) {
super(`HTTPError: unsuccessful status code (${code}): ${body}`);
this.statusCode = code;
this.responseBody = body;
}
}

export class SyncError extends Error {
meta;
reason;
meta?:
| {
isMissingKey: boolean;
}
| {
error: { message: string; stack: string };
query: { sql: string; params: Array<string | number> };
};
reason: string;

constructor(reason, meta?) {
constructor(
reason: string,
meta?:
| {
isMissingKey: boolean;
}
| {
error: { message: string; stack: string };
query: { sql: string; params: Array<string | number> };
},
) {
super('SyncError: ' + reason);
this.reason = reason;
this.meta = meta;
Expand All @@ -46,14 +62,20 @@ export class RuleError extends Error {
}
}

export function APIError(msg, meta?) {
return { type: 'APIError', message: msg, meta };
export function APIError(msg: string) {
return { type: 'APIError', message: msg };
}

export function FileDownloadError(reason, meta?) {
export function FileDownloadError(
reason: string,
meta?: { fileId?: string; isMissingKey?: boolean },
) {
return { type: 'FileDownloadError', reason, meta };
}

export function FileUploadError(reason, meta?) {
export function FileUploadError(
reason: string,
meta?: { isMissingKey: boolean },
) {
return { type: 'FileUploadError', reason, meta };
}
Loading