Reduce Community lint type-safety warnings

This commit is contained in:
vorotamoroz
2026-07-20 18:08:09 +00:00
parent 2cf535332b
commit 104eeadb4b
29 changed files with 664 additions and 318 deletions
+27
View File
@@ -0,0 +1,27 @@
import type { App } from "@/deps.ts";
function getSettingsManager(app: App): Record<string, unknown> {
const manager: unknown = Reflect.get(app, "setting");
if (typeof manager !== "object" || manager === null) {
throw new TypeError("Obsidian does not expose the settings manager");
}
return manager as Record<string, unknown>;
}
function invokeSettingsMethod(app: App, methodName: string, args: unknown[] = []): void {
const manager = getSettingsManager(app);
const method = manager[methodName];
if (typeof method !== "function") {
throw new TypeError(`Obsidian does not expose settings.${methodName}`);
}
Reflect.apply(method, manager, args);
}
export function openObsidianSettings(app: App, tabId: string): void {
invokeSettingsMethod(app, "open");
invokeSettingsMethod(app, "openTabById", [tabId]);
}
export function closeObsidianSettings(app: App): void {
invokeSettingsMethod(app, "close");
}