refactor(client/ts): use filtered generics for context menu commands

This commit is contained in:
Elian Doran
2024-12-22 19:31:29 +02:00
parent 19652fbbce
commit b01725101d
9 changed files with 115 additions and 50 deletions

View File

@@ -1,4 +1,5 @@
import utils from '../services/utils.js';
import { CommandMappings, CommandNames } from './app_context.js';
/**
* Abstract class for all components in the Trilium's frontend.
@@ -84,7 +85,8 @@ export default class Component {
return promises.length > 0 ? Promise.all(promises) : null;
}
triggerCommand(name: string, data = {}): Promise<unknown> | undefined | null {
triggerCommand<K extends CommandNames>(name: string, _data?: CommandMappings[K]): Promise<unknown> | undefined | null {
const data = _data || {};
const fun = (this as any)[`${name}Command`];
if (fun) {