From b1b266e83caad578d47c28d59779e394cef8bda1 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins <matiss@mja.lv> Date: Thu, 8 Feb 2024 20:53:05 +0000 Subject: [PATCH] :bug: (typescript) patching sendCatch type (#2343) * :bug: (typescript) patching sendCatch type * Release notes --- .../loot-core/src/platform/client/fetch/index.d.ts | 13 ++++++++++++- .../src/platform/client/fetch/index.web.ts | 1 - upcoming-release-notes/2343.md | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 upcoming-release-notes/2343.md 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 5ae4f2d3e..7ca6e52bc 100644 --- a/packages/loot-core/src/platform/client/fetch/index.d.ts +++ b/packages/loot-core/src/platform/client/fetch/index.d.ts @@ -4,6 +4,14 @@ import type { ServerEvents } from '../../../types/server-events'; export function init(socketName: string): Promise<unknown>; export type Init = typeof init; +export function send<K extends keyof Handlers>( + name: K, + args?: Parameters<Handlers[K]>[0], + options?: { catchErrors: true }, +): ReturnType< + | { data: Handlers[K] } + | { error: { type: 'APIError' | 'InternalError'; message: string } } +>; export function send<K extends keyof Handlers>( name: K, args?: Parameters<Handlers[K]>[0], @@ -14,7 +22,10 @@ export type Send = typeof send; export function sendCatch<K extends keyof Handlers>( name: K, args?: Parameters<Handlers[K]>[0], -): ReturnType<Handlers[K]>; +): ReturnType< + | { data: Handlers[K] } + | { error: { type: 'APIError' | 'InternalError'; message: string } } +>; export type SendCatch = typeof sendCatch; export function listen<K extends keyof ServerEvents>( 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 055871e88..c74ce488a 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,6 @@ export const init: T.Init = async function () { return new Promise(connectSocket); }; -// @ts-expect-error Figure out why typechecker is suddenly breaking here export const send: T.Send = function ( name, args, diff --git a/upcoming-release-notes/2343.md b/upcoming-release-notes/2343.md new file mode 100644 index 000000000..0466048df --- /dev/null +++ b/upcoming-release-notes/2343.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MatissJanis] +--- + +Patching an incorrect TypeScript type definition used for `sendCatch` method return value. -- GitLab