1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Tweak typing of request channel listeners to get rid of unexpected undefined

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-05-27 14:56:33 +03:00
parent a99f62090a
commit 6103f2a9ef
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 14 additions and 4 deletions

View File

@ -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<TChannel extends RequestChannel<any, any>> {
channel: TChannel;
handler: (request: TChannel["_requestSignature"]) => TChannel["_responseSignature"];
handler: (
request: SetRequired<TChannel, "_requestSignature">["_requestSignature"]
) =>
| SetRequired<TChannel, "_responseSignature">["_responseSignature"]
| Promise<
SetRequired<TChannel, "_responseSignature">["_responseSignature"]
>;
}
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<any, any>>>(

View File

@ -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<AppPathsChannel> => {
const channel = di.inject(appPathsChannelInjectable);
const appPaths = di.inject(appPathsInjectable);
return ({
return {
channel,
handler: () => appPaths,
});
};
},
injectionToken: requestChannelListenerInjectionToken,
});