diff --git a/src/common/application-update/application-update-status-channel.injectable.ts b/src/common/application-update/application-update-status-channel.injectable.ts index 127f0cec2f..251bc7e992 100644 --- a/src/common/application-update/application-update-status-channel.injectable.ts +++ b/src/common/application-update/application-update-status-channel.injectable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { JsonObject } from "type-fest"; import type { MessageChannel } from "../channel/message-channel-injection-token"; import { messageChannelInjectionToken } from "../channel/message-channel-injection-token"; @@ -12,7 +13,7 @@ export type ApplicationUpdateStatusEventId = | "download-for-update-started" | "download-for-update-failed"; -export interface ApplicationUpdateStatusChannelMessage { eventId: ApplicationUpdateStatusEventId; version?: string } +export interface ApplicationUpdateStatusChannelMessage extends JsonObject { eventId: ApplicationUpdateStatusEventId; version?: string } export type ApplicationUpdateStatusChannel = MessageChannel; const applicationUpdateStatusChannelInjectable = getInjectable({ diff --git a/src/common/ask-boolean/ask-boolean-question-channel.injectable.ts b/src/common/ask-boolean/ask-boolean-question-channel.injectable.ts index 8ac603b2d2..4027fa1513 100644 --- a/src/common/ask-boolean/ask-boolean-question-channel.injectable.ts +++ b/src/common/ask-boolean/ask-boolean-question-channel.injectable.ts @@ -3,10 +3,11 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { JsonObject } from "type-fest"; import type { MessageChannel } from "../channel/message-channel-injection-token"; import { messageChannelInjectionToken } from "../channel/message-channel-injection-token"; -export interface AskBooleanQuestionParameters { id: string; title: string; question: string } +export interface AskBooleanQuestionParameters extends JsonObject { id: string; title: string; question: string } export type AskBooleanQuestionChannel = MessageChannel; const askBooleanQuestionChannelInjectable = getInjectable({ diff --git a/src/common/channel/enlist-message-channel-listener-injection-token.ts b/src/common/channel/enlist-message-channel-listener-injection-token.ts index e75a50468d..fa6983e130 100644 --- a/src/common/channel/enlist-message-channel-listener-injection-token.ts +++ b/src/common/channel/enlist-message-channel-listener-injection-token.ts @@ -7,7 +7,7 @@ import type { MessageChannel } from "./message-channel-injection-token"; import type { MessageChannelListener } from "./message-channel-listener-injection-token"; export type EnlistMessageChannelListener = < - TChannel extends MessageChannel, + TChannel extends MessageChannel, >(listener: MessageChannelListener) => () => void; export const enlistMessageChannelListenerInjectionToken = diff --git a/src/common/channel/message-channel-injection-token.ts b/src/common/channel/message-channel-injection-token.ts index e7502c6e34..3141acedf3 100644 --- a/src/common/channel/message-channel-injection-token.ts +++ b/src/common/channel/message-channel-injection-token.ts @@ -4,8 +4,9 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; +import type { JsonValue } from "type-fest"; -export interface MessageChannel { +export interface MessageChannel { id: string; _messageSignature?: Message; } diff --git a/src/common/channel/message-to-channel-injection-token.ts b/src/common/channel/message-to-channel-injection-token.ts index d70be48e5e..8c5f03b9ee 100644 --- a/src/common/channel/message-to-channel-injection-token.ts +++ b/src/common/channel/message-to-channel-injection-token.ts @@ -3,6 +3,7 @@ * 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 { MessageChannel } from "./message-channel-injection-token"; export interface MessageToChannel { @@ -10,9 +11,9 @@ export interface MessageToChannel { channel: TChannel, ): void; - , TMessage>( + >( channel: TChannel, - message: TMessage + message: SetRequired["_messageSignature"], ): void; } diff --git a/src/main/channel/message-to-channel.injectable.ts b/src/main/channel/message-to-channel.injectable.ts index 7ffd82b96e..072726a52b 100644 --- a/src/main/channel/message-to-channel.injectable.ts +++ b/src/main/channel/message-to-channel.injectable.ts @@ -17,7 +17,7 @@ const messageToChannelInjectable = getInjectable({ // TODO: Figure out way to improve typing in internals // Notice that this should be injected using "messageToChannelInjectionToken" which is typed correctly. - return (channel: MessageChannel, message?: unknown) => { + return (channel: MessageChannel, message?: unknown) => { const visibleWindows = pipeline( getAllLensWindows(), filter((lensWindow) => !!lensWindow.visible), diff --git a/src/renderer/channel/message-to-channel.injectable.ts b/src/renderer/channel/message-to-channel.injectable.ts index 921351dc60..d6082baac6 100644 --- a/src/renderer/channel/message-to-channel.injectable.ts +++ b/src/renderer/channel/message-to-channel.injectable.ts @@ -15,7 +15,7 @@ const messageToChannelInjectable = getInjectable({ // TODO: Figure out way to improve typing in internals // Notice that this should be injected using "messageToChannelInjectionToken" which is typed correctly. - return (channel: MessageChannel, message?: unknown) => { + return (channel: MessageChannel, message?: unknown) => { sendToMain(channel.id, message); }; }, diff --git a/src/renderer/channel/send-to-main.injectable.ts b/src/renderer/channel/send-to-main.injectable.ts index a2b135ebd3..e9f68a9324 100644 --- a/src/renderer/channel/send-to-main.injectable.ts +++ b/src/renderer/channel/send-to-main.injectable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { JsonValue } from "type-fest"; import ipcRendererInjectable from "./ipc-renderer.injectable"; const sendToMainInjectable = getInjectable({ @@ -12,7 +13,7 @@ const sendToMainInjectable = getInjectable({ const ipcRenderer = di.inject(ipcRendererInjectable); // TODO: Figure out way to improve typing in internals - return (channelId: string, message: any) => { + return (channelId: string, message: JsonValue extends T ? T : never ) => { ipcRenderer.send(channelId, ...(message ? [message] : [])); }; }, diff --git a/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts b/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts index 5c2b839ad9..01af393020 100644 --- a/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts +++ b/src/test-utils/channel-fakes/override-messaging-from-main-to-window.ts @@ -13,7 +13,7 @@ import assert from "assert"; export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => { const messageChannelListenerFakesForRenderer = new Map< string, - Set>> + Set>> >(); mainDi.override( @@ -73,14 +73,14 @@ export const overrideMessagingFromMainToWindow = (mainDi: DiContainer) => { // TODO: Figure out typing listeners.add( - listener as unknown as MessageChannelListener>, + listener as unknown as MessageChannelListener>, ); return () => { // TODO: Figure out typing listeners.delete( listener as unknown as MessageChannelListener< - MessageChannel + MessageChannel >, ); }; diff --git a/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts b/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts index 01538dc920..7141160639 100644 --- a/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts +++ b/src/test-utils/channel-fakes/override-messaging-from-window-to-main.ts @@ -12,7 +12,7 @@ import sendToMainInjectable from "../../renderer/channel/send-to-main.injectable export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => { const messageChannelListenerFakesForMain = new Map< string, - Set>> + Set>> >(); mainDi.override( @@ -33,13 +33,13 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => { // TODO: Figure out typing listeners.add( - listener as unknown as MessageChannelListener>, + listener as unknown as MessageChannelListener>, ); return () => { // TODO: Figure out typing listeners.delete( - listener as unknown as MessageChannelListener>, + listener as unknown as MessageChannelListener>, ); }; },