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:
parent
a99f62090a
commit
6103f2a9ef
@ -3,11 +3,19 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type { SetRequired } from "type-fest";
|
||||||
import type { RequestChannel } from "./request-channel-injection-token";
|
import type { RequestChannel } from "./request-channel-injection-token";
|
||||||
|
|
||||||
export interface RequestChannelListener<TChannel extends RequestChannel<any, any>> {
|
export interface RequestChannelListener<TChannel extends RequestChannel<any, any>> {
|
||||||
channel: TChannel;
|
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>>>(
|
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<any, any>>>(
|
||||||
|
|||||||
@ -3,21 +3,23 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
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 { 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 appPathsChannelInjectable from "../../common/app-paths/app-paths-channel.injectable";
|
||||||
import appPathsInjectable from "../../common/app-paths/app-paths.injectable";
|
import appPathsInjectable from "../../common/app-paths/app-paths.injectable";
|
||||||
|
|
||||||
const appPathsRequestChannelListenerInjectable = getInjectable({
|
const appPathsRequestChannelListenerInjectable = getInjectable({
|
||||||
id: "app-paths-request-channel-listener",
|
id: "app-paths-request-channel-listener",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di): RequestChannelListener<AppPathsChannel> => {
|
||||||
const channel = di.inject(appPathsChannelInjectable);
|
const channel = di.inject(appPathsChannelInjectable);
|
||||||
const appPaths = di.inject(appPathsInjectable);
|
const appPaths = di.inject(appPathsInjectable);
|
||||||
|
|
||||||
return ({
|
return {
|
||||||
channel,
|
channel,
|
||||||
handler: () => appPaths,
|
handler: () => appPaths,
|
||||||
});
|
};
|
||||||
},
|
},
|
||||||
injectionToken: requestChannelListenerInjectionToken,
|
injectionToken: requestChannelListenerInjectionToken,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user