diff --git a/src/modal.ts b/src/modal.ts index 55f088c..fa210de 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -1,6 +1,6 @@ 'use strict'; -import { Modal } from 'obsidian'; +import { type App, Modal } from 'obsidian'; import type { CardPatch, PluginHost, ResolvedCard } from './types'; import { addTextButton } from './ui-helpers'; @@ -9,7 +9,7 @@ export class CardEditModal extends Modal { card: ResolvedCard; onSave: (patch: CardPatch) => void | Promise; - constructor(app, plugin: PluginHost, card: ResolvedCard, onSave: (patch: CardPatch) => void | Promise) { + constructor(app: App, plugin: PluginHost, card: ResolvedCard, onSave: (patch: CardPatch) => void | Promise) { super(app); this.plugin = plugin; this.card = card || ({} as ResolvedCard); diff --git a/src/settings-tab.ts b/src/settings-tab.ts index 39d5134..c5c83ee 100644 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -1,6 +1,6 @@ 'use strict'; -import { Notice, PluginSettingTab, requestUrl, Setting } from 'obsidian'; +import { type App, Notice, type Plugin, PluginSettingTab, requestUrl, Setting } from 'obsidian'; import { resolveCliPath, runCli } from './cli'; import { testApiBackend } from './providers'; import { @@ -36,10 +36,10 @@ async function testBackend(settings) { } export class ParallelReaderSettingTab extends PluginSettingTab { - plugin: PluginHost; + plugin: Plugin & PluginHost; - constructor(app, plugin: PluginHost) { - super(app, plugin as any); + constructor(app: App, plugin: Plugin & PluginHost) { + super(app, plugin); this.plugin = plugin; } diff --git a/src/types.ts b/src/types.ts index 4bf566b..d6c9de5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,7 @@ 'use strict'; +import type { App, PluginManifest, TFile } from 'obsidian'; + /* ---------- Card types ---------- */ /** Raw card as returned by the LLM and stored in cache (no computed fields). */ @@ -114,16 +116,16 @@ export interface PromptPair { * main.ts and the extracted modules. */ export interface PluginHost { - app: { vault: any; workspace: any }; + app: App; settings: PluginSettings; cache: Record; - manifest?: { id: string }; + manifest: PluginManifest; t(key: string, vars?: Record): string; - isGeneratingFile(file: any): boolean; - cancelGenerationForFile(file: any): boolean; - runForFile(file: any, force: boolean): Promise; + isGeneratingFile(file: TFile | null): boolean; + cancelGenerationForFile(file: TFile | null): boolean; + runForFile(file: TFile | null, force: boolean): Promise; copyCurrentViewMarkdown(): Promise; - scrollEditorToLine(line: number, file: any): Promise; + scrollEditorToLine(line: number, file: TFile | null): Promise; cacheReplaceCards(filePath: string, cards: ResolvedCard[]): Promise; saveSettings(): Promise; saveSettingsDebounced(delayMs?: number): void; diff --git a/src/vault.ts b/src/vault.ts index 660573c..8e96783 100644 --- a/src/vault.ts +++ b/src/vault.ts @@ -1,6 +1,8 @@ 'use strict'; -export function normalizeVaultPath(path) { +import type { App } from 'obsidian'; + +export function normalizeVaultPath(path: string): string { return String(path || '') .split('/') .map((part) => part.trim()) @@ -8,14 +10,14 @@ export function normalizeVaultPath(path) { .join('/'); } -export function folderPathsForTarget(folderPath) { +export function folderPathsForTarget(folderPath: string): string[] { const normalized = normalizeVaultPath(folderPath); if (!normalized) return []; const parts = normalized.split('/'); return parts.map((_, idx) => parts.slice(0, idx + 1).join('/')); } -export async function ensureVaultFolder(app, folderPath) { +export async function ensureVaultFolder(app: App, folderPath: string) { for (const folder of folderPathsForTarget(folderPath)) { if (app.vault.getAbstractFileByPath(folder)) continue; try {