From d5ea716ba737d3525234ef6476bf9a8c448f21eb Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Mon, 13 Jan 2025 22:40:13 -0500 Subject: [PATCH 1/4] Add release notes --- upcoming-release-notes/4145.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/4145.md diff --git a/upcoming-release-notes/4145.md b/upcoming-release-notes/4145.md new file mode 100644 index 00000000000..d8f8660e424 --- /dev/null +++ b/upcoming-release-notes/4145.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [jfdoming] +--- + +Fix types of `send` function From c17b83e94e1030e141f119bdf84093f9802288ab Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Mon, 13 Jan 2025 21:53:47 -0500 Subject: [PATCH 2/4] Fix types of `send` function --- .../src/platform/client/fetch/index.d.ts | 24 ++++++++++++------- .../src/platform/client/fetch/index.web.ts | 8 ++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/loot-core/src/platform/client/fetch/index.d.ts b/packages/loot-core/src/platform/client/fetch/index.d.ts index d6e4d4a31cd..dcb660ea902 100644 --- a/packages/loot-core/src/platform/client/fetch/index.d.ts +++ b/packages/loot-core/src/platform/client/fetch/index.d.ts @@ -7,25 +7,31 @@ export type Init = typeof init; export function send( name: K, - args?: Parameters[0], - options?: { catchErrors: true }, -): ReturnType< - | { data: Handlers[K] } - | { error: { type: 'APIError' | 'InternalError'; message: string } } + args: Parameters[0], + options: { catchErrors: true }, +): Promise< + | { data: Awaited>; error: undefined } + | { + data: undefined; + error: { type: 'APIError' | 'InternalError'; message: string }; + } >; export function send( name: K, args?: Parameters[0], options?: { catchErrors?: boolean }, -): ReturnType; +): Promise>>; export type Send = typeof send; export function sendCatch( name: K, args?: Parameters[0], -): ReturnType< - | { data: Handlers[K] } - | { error: { type: 'APIError' | 'InternalError'; message: string } } +): Promise< + | { data: Awaited>; error: undefined } + | { + data: undefined; + error: { type: 'APIError' | 'InternalError'; message: string }; + } >; export type SendCatch = typeof sendCatch; diff --git a/packages/loot-core/src/platform/client/fetch/index.web.ts b/packages/loot-core/src/platform/client/fetch/index.web.ts index c74ce488a6f..1b165af397d 100644 --- a/packages/loot-core/src/platform/client/fetch/index.web.ts +++ b/packages/loot-core/src/platform/client/fetch/index.web.ts @@ -78,11 +78,7 @@ export const init: T.Init = async function () { return new Promise(connectSocket); }; -export const send: T.Send = function ( - name, - args, - { catchErrors = false } = {}, -) { +export const send = function (name, args, { catchErrors = false } = {}) { return new Promise((resolve, reject) => { const id = uuidv4(); replyHandlers.set(id, { resolve, reject }); @@ -107,7 +103,7 @@ export const send: T.Send = function ( }); }; -export const sendCatch: T.SendCatch = function (name, args) { +export const sendCatch = function (name, args) { return send(name, args, { catchErrors: true }); }; From 84fd2b8f34b3c123a048f72a6ef1d592901e4e9a Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Tue, 14 Jan 2025 00:50:01 -0500 Subject: [PATCH 3/4] Fix `send` types in a number of places --- .../src/components/modals/EditAccess.tsx | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/desktop-client/src/components/modals/EditAccess.tsx b/packages/desktop-client/src/components/modals/EditAccess.tsx index aaef96cfb3d..02d595714a9 100644 --- a/packages/desktop-client/src/components/modals/EditAccess.tsx +++ b/packages/desktop-client/src/components/modals/EditAccess.tsx @@ -4,7 +4,6 @@ import { Trans, useTranslation } from 'react-i18next'; import { addNotification, popModal, signOut } from 'loot-core/client/actions'; import { send } from 'loot-core/platform/client/fetch'; import { getUserAccessErrors } from 'loot-core/shared/errors'; -import { type Handlers } from 'loot-core/types/handlers'; import { type UserAccessEntity } from 'loot-core/types/models/userAccess'; import { useDispatch } from '../../redux'; @@ -34,22 +33,20 @@ export function EditUserAccess({ const [availableUsers, setAvailableUsers] = useState<[string, string][]>([]); useEffect(() => { - send('access-get-available-users', defaultUserAccess.fileId).then( - (data: Awaited>) => { - if ('error' in data) { - setSetError(data.error); - } else { - setAvailableUsers( - data.map(user => [ - user.userId, - user.displayName - ? `${user.displayName} (${user.userName})` - : user.userName, - ]), - ); - } - }, - ); + send('access-get-available-users', defaultUserAccess.fileId).then(data => { + if ('error' in data) { + setSetError(data.error); + } else { + setAvailableUsers( + data.map(user => [ + user.userId, + user.displayName + ? `${user.displayName} (${user.userName})` + : user.userName, + ]), + ); + } + }); }, [defaultUserAccess.fileId]); async function onSave(close: () => void) { From 30c2e28b2f68949c55f0b08ca6548db02b61cf9a Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Wed, 22 Jan 2025 20:18:34 -0500 Subject: [PATCH 4/4] PR feedback --- .../src/platform/client/fetch/index.browser.ts | 10 ++++------ .../loot-core/src/platform/client/fetch/index.web.ts | 7 +++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/loot-core/src/platform/client/fetch/index.browser.ts b/packages/loot-core/src/platform/client/fetch/index.browser.ts index 6f212a34658..a235312a045 100644 --- a/packages/loot-core/src/platform/client/fetch/index.browser.ts +++ b/packages/loot-core/src/platform/client/fetch/index.browser.ts @@ -147,10 +147,9 @@ export const init: T.Init = async function (worker) { }; export const send: T.Send = function ( - name, - args, - { catchErrors = false } = {}, -) { + ...params: Parameters +): ReturnType { + const [name, args, { catchErrors = false } = {}] = params; return new Promise((resolve, reject) => { const id = uuidv4(); @@ -167,8 +166,7 @@ export const send: T.Send = function ( } else { globalWorker.postMessage(message); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - }) as any; + }); }; export const sendCatch: T.SendCatch = function (name, args) { diff --git a/packages/loot-core/src/platform/client/fetch/index.web.ts b/packages/loot-core/src/platform/client/fetch/index.web.ts index 1b165af397d..b28c1d680a6 100644 --- a/packages/loot-core/src/platform/client/fetch/index.web.ts +++ b/packages/loot-core/src/platform/client/fetch/index.web.ts @@ -78,7 +78,10 @@ export const init: T.Init = async function () { return new Promise(connectSocket); }; -export const send = function (name, args, { catchErrors = false } = {}) { +export const send: T.Send = function ( + ...params: Parameters +): ReturnType { + const [name, args, { catchErrors = false } = {}] = params; return new Promise((resolve, reject) => { const id = uuidv4(); replyHandlers.set(id, { resolve, reject }); @@ -103,7 +106,7 @@ export const send = function (name, args, { catchErrors = false } = {}) { }); }; -export const sendCatch = function (name, args) { +export const sendCatch: T.SendCatch = function (name, args) { return send(name, args, { catchErrors: true }); };