From 774b46be945eccb7f30589668d339b189b6b48bf Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 2 Jun 2024 19:40:36 +0900 Subject: [PATCH] better types --- packages/frontend/src/scripts/post-message.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/scripts/post-message.ts b/packages/frontend/src/scripts/post-message.ts index 6f63d3c7da..3f94988493 100644 --- a/packages/frontend/src/scripts/post-message.ts +++ b/packages/frontend/src/scripts/post-message.ts @@ -11,10 +11,18 @@ export const postMessageEventTypes = [ export type PostMessageEventType = typeof postMessageEventTypes[number]; -export type MiPostMessageEvent = { - type: PostMessageEventType; +export interface PostMessageEventPayload extends Record { + 'misskey:shareForm:shareCompleted': undefined; + 'misskey:embed:ready': undefined; + 'misskey:embed:changeHeight': { + height: number; + }; +}; + +export type MiPostMessageEvent = { + type: T; iframeId?: string; - payload?: any; + payload?: PostMessageEventPayload[T]; }; let defaultIframeId: string | null = null; @@ -27,7 +35,7 @@ export function setIframeId(id: string): void { /** * 親フレームにイベントを送信 */ -export function postMessageToParentWindow(type: PostMessageEventType, payload?: any, iframeId: string | null = null): void { +export function postMessageToParentWindow(type: T, payload?: PostMessageEventPayload[T], iframeId: string | null = null): void { let _iframeId = iframeId; if (_iframeId == null) { _iframeId = defaultIframeId;