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) { 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 0a7f0d0569a..defc478021d 100644 --- a/packages/loot-core/src/platform/client/fetch/index.browser.ts +++ b/packages/loot-core/src/platform/client/fetch/index.browser.ts @@ -151,10 +151,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(); @@ -171,8 +170,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.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..b28c1d680a6 100644 --- a/packages/loot-core/src/platform/client/fetch/index.web.ts +++ b/packages/loot-core/src/platform/client/fetch/index.web.ts @@ -79,10 +79,9 @@ export const init: T.Init = async function () { }; 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(); replyHandlers.set(id, { resolve, reject }); 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