From 6103f2a9ef3bbc5ab596d310649e2c654898b0b0 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 27 May 2022 14:56:33 +0300 Subject: [PATCH] Tweak typing of request channel listeners to get rid of unexpected undefined Signed-off-by: Janne Savolainen --- .../request-channel-listener-injection-token.ts | 10 +++++++++- .../app-paths-request-channel-listener.injectable.ts | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/channel/request-channel-listener-injection-token.ts b/src/common/channel/request-channel-listener-injection-token.ts index 0455bc2ec2..690b96d9dc 100644 --- a/src/common/channel/request-channel-listener-injection-token.ts +++ b/src/common/channel/request-channel-listener-injection-token.ts @@ -3,11 +3,19 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectionToken } from "@ogre-tools/injectable"; +import type { SetRequired } from "type-fest"; import type { RequestChannel } from "./request-channel-injection-token"; export interface RequestChannelListener> { channel: TChannel; - handler: (request: TChannel["_requestSignature"]) => TChannel["_responseSignature"]; + + handler: ( + request: SetRequired["_requestSignature"] + ) => + | SetRequired["_responseSignature"] + | Promise< + SetRequired["_responseSignature"] + >; } export const requestChannelListenerInjectionToken = getInjectionToken>>( diff --git a/src/main/app-paths/app-paths-request-channel-listener.injectable.ts b/src/main/app-paths/app-paths-request-channel-listener.injectable.ts index 9cf12f5e65..3fd3aec572 100644 --- a/src/main/app-paths/app-paths-request-channel-listener.injectable.ts +++ b/src/main/app-paths/app-paths-request-channel-listener.injectable.ts @@ -3,21 +3,23 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { RequestChannelListener } from "../../common/channel/request-channel-listener-injection-token"; import { requestChannelListenerInjectionToken } from "../../common/channel/request-channel-listener-injection-token"; +import type { AppPathsChannel } from "../../common/app-paths/app-paths-channel.injectable"; import appPathsChannelInjectable from "../../common/app-paths/app-paths-channel.injectable"; import appPathsInjectable from "../../common/app-paths/app-paths.injectable"; const appPathsRequestChannelListenerInjectable = getInjectable({ id: "app-paths-request-channel-listener", - instantiate: (di) => { + instantiate: (di): RequestChannelListener => { const channel = di.inject(appPathsChannelInjectable); const appPaths = di.inject(appPathsInjectable); - return ({ + return { channel, handler: () => appPaths, - }); + }; }, injectionToken: requestChannelListenerInjectionToken, });