Skip to content

ExtractEventMap<T>

Derives an event map ({ eventName: [callbackArgs] }) from a type exposing an overloaded on(name, callback) method — e.g. Obsidian’s Workspace / Vault / MetadataCache. Each on overload becomes one entry keyed by the event name, with the callback’s parameters as a labeled tuple; the wide on(name: string, …) catch-all overload is dropped. The map auto-tracks upstream overloads (no hand-authoring). It cannot reconstruct genuinely generic overloads, but Obsidian’s event overloads are all concrete string-literal ones.

Import:

import type { ExtractEventMap } from 'obsidian-dev-utils/type';

Example:

type WorkspaceEventMap = ExtractEventMap<Workspace>;
// { 'file-menu': [menu: Menu, file: TAbstractFile, source: string, leaf?: WorkspaceLeaf]; … }

Signature:

export type ExtractEventMap<T extends EventsWithOn>

Signature:

type ExtractEventMap<T> = UnionToIntersection<EntryOfOverload<OverloadUnion<T['on']>>>

Type: UnionToIntersection<EntryOfOverload<OverloadUnion<T[‘on’]>>>