@microsoft/teams.apps
Version:
<p> <a href="https://www.npmjs.com/package/@microsoft/teams.apps" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.apps/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.apps?activeTab=code
26 lines (25 loc) • 1.23 kB
TypeScript
import { IEvents } from '../events';
import { IPlugin } from './plugin';
import { UnionToIntersection } from './union-to-intersection';
/**
* Extracts the events from a plugin if it extends PluginWithEvents
*/
export type PluginEvents<T> = T extends IPlugin<any, infer Events> ? Events : {};
type MergePluginEventMaps<TPlugins> = UnionToIntersection<TPlugins extends readonly unknown[] ? PluginEvents<TPlugins[number]> : PluginEvents<TPlugins>>;
/**
* Combines two sets of event types:
* 1. Base events from IEvents interface (these are core-events)
* 2. Custom events from all registered plugins that extend PluginWithEvents
*
* For any given event key K:
* - If K exists in IEvents, use the event type from IEvents (i.e. prioritizes core-events)
* - If K exists in plugin events, use the event type from plugins
* - Otherwise, the type is never
*
* This creates a unified event type map that prioritizes base events
* while still including all plugin-specific events.
*/
export type AppEvents<TPlugins> = {
[K in keyof IEvents | keyof MergePluginEventMaps<TPlugins>]: K extends keyof IEvents ? IEvents[K] : K extends keyof MergePluginEventMaps<TPlugins> ? MergePluginEventMaps<TPlugins>[K] : never;
};
export {};