Auto tagging obsidian notes w/ AI
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: replace any type assertions with proper typings

- Removed all `as any` type assertions
- Added proper error type checking for error handling
- Used Record<string, unknown> instead of any for frontmatter
- Added property existence check before accessing app.setting

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

+15 -8
+15 -8
main.ts
··· 143 143 const tags = await this.generateTags(content); 144 144 await this.updateNoteFrontmatter(file, tags); 145 145 new Notice(`Successfully added tags: ${tags.join(", ")}`); 146 - } catch (error: any) { 146 + } catch (error) { 147 147 console.error("Error tagging note:", error); 148 - new Notice(`Error tagging note: ${error.message}`); 148 + const errorMessage = error instanceof Error ? error.message : String(error); 149 + new Notice(`Error tagging note: ${errorMessage}`); 149 150 } 150 151 } 151 152 ··· 169 170 const tags = await this.generateTags(content); 170 171 await this.updateNoteFrontmatter(file, tags); 171 172 successful++; 172 - } catch (error: any) { 173 + } catch (error) { 173 174 console.error(`Error tagging note ${file.path}:`, error); 174 175 } 175 176 ··· 235 236 .split(",") 236 237 .map((tag: string) => tag.trim()) 237 238 .filter((tag: string) => tag.length > 0); 238 - } catch (error: any) { 239 + } catch (error) { 239 240 console.error("Error calling Claude API:", error); 240 - throw new Error(`Failed to generate tags: ${error.message}`); 241 + const errorMessage = error instanceof Error ? error.message : String(error); 242 + throw new Error(`Failed to generate tags: ${errorMessage}`); 241 243 } 242 244 } 243 245 ··· 245 247 // Read the file content 246 248 const content = await this.app.vault.read(file); 247 249 248 - let frontmatter: any = {}; 250 + let frontmatter: Record<string, unknown> = {}; 249 251 let fileContent = content; 250 252 const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n/); 251 253 ··· 324 326 settingsButton.addEventListener("click", () => { 325 327 this.close(); 326 328 // Open settings tab 327 - (this.app as any).setting.open(); 328 - (this.app as any).setting.openTabById("obsidian-sample-plugin"); 329 + // Using type assertion with a more specific interface would be better 330 + // if we had access to the internal Obsidian API types 331 + if ('setting' in this.app) { 332 + const appWithSetting = this.app as unknown as { setting: { open: () => void; openTabById: (id: string) => void } }; 333 + appWithSetting.setting.open(); 334 + appWithSetting.setting.openTabById("obsidian-sample-plugin"); 335 + } 329 336 }); 330 337 331 338 const cancelButton = buttonContainer.createEl("button", {