Adding strong checks on messages exchanged using generic-type-guard
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isChatEvent =
|
||||
new tg.IsInterface().withProperties({
|
||||
message: tg.isString,
|
||||
author: tg.isString,
|
||||
}).get();
|
||||
export type ChatEvent = tg.GuardedType<typeof isChatEvent>;
|
||||
@@ -0,0 +1,7 @@
|
||||
interface IframeEvent {
|
||||
type: string;
|
||||
data: unknown;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const isIframeEventWrapper = (event: any): event is IframeEvent => typeof event.type === 'string' && typeof event.data === 'object';
|
||||
Reference in New Issue
Block a user