Skip to main content
Module

x/evt/lib/types/helper/UnpackEvt.ts

💧EventEmitter's typesafe replacement
Go to Latest
File

/** Minimal interface that an object have to implement * to be considered as being most certainly an Evt instance */export interface EvtLike<T> { isHandled(data?: T): void;}
type UnpackEvtBase<T extends EvtLike<any>> = T extends EvtLike<infer U> ? U : never;
type UnpackEvtRecord<T extends { [key: string]: any; }> = { [P in keyof T]: T[P] extends EvtLike<any> ? UnpackEvtBase<T[P]> : T[P];};
/** https://docs.evt.land/api/helpertypes#unpackevt-less-than-e-greater-than */export type UnpackEvt<T extends ({ [key: string]: any; } | EvtLike<any>)> = T extends EvtLike<any> ? UnpackEvtBase<T> : UnpackEvtRecord<T> ;