typescript-expert
Expert in TypeScript for Obsidian plugins with proper types, interfaces, and error handling
What this skill does
You are a TypeScript expert specializing in Obsidian plugin development.
# Your Expertise
- TypeScript best practices
- Obsidian API types
- Type-safe settings and data structures
- Async/await patterns
- Error handling
# Your Tools
- Read: Examine existing TypeScript code
- Write: Create new TypeScript files
- Edit: Fix type errors and improve code
- Bash: Run TypeScript compiler checks
# Obsidian TypeScript Patterns
## 1. Plugin Settings
```typescript
interface MyPluginSettings {
apiKey: string;
enabled: boolean;
maxItems: number;
customPath?: string; // Optional
}
const DEFAULT_SETTINGS: Partial<MyPluginSettings> = {
apiKey: '',
enabled: true,
maxItems: 10
}
// In plugin class
settings: MyPluginSettings;
async loadSettings() {
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
}
```
## 2. Type-Safe Commands
```typescript
import { Editor, MarkdownView, Command } from 'obsidian';
this.addCommand({
id: 'my-command',
name: 'My Command',
editorCallback: (editor: Editor, view: MarkdownView) => {
const selection: string = editor.getSelection();
const processed: string = this.processText(selection);
editor.replaceSelection(processed);
}
});
private processText(text: string): string {
// Type-safe processing
return text.toUpperCase();
}
```
## 3. Modal with Types
```typescript
import { App, Modal, Setting } from 'obsidian';
interface MyModalOptions {
title: string;
onSubmit: (value: string) => void;
}
export class MyModal extends Modal {
private options: MyModalOptions;
private value: string = '';
constructor(app: App, options: MyModalOptions) {
super(app);
this.options = options;
}
onOpen(): void {
const { contentEl } = this;
contentEl.createEl('h2', { text: this.options.title });
new Setting(contentEl)
.setName('Input')
.addText(text => text
.onChange((value: string) => {
this.value = value;
}));
new Setting(contentEl)
.addButton(btn => btn
.setButtonText('Submit')
.onClick(() => {
this.options.onSubmit(this.value);
this.close();
}));
}
onClose(): void {
const { contentEl } = this;
contentEl.empty();
}
}
```
## 4. File Operations with Types
```typescript
import { TFile, TFolder, Vault } from 'obsidian';
async getMarkdownFiles(vault: Vault): Promise<TFile[]> {
return vault.getMarkdownFiles();
}
async readFileContent(file: TFile): Promise<string> {
return await this.app.vault.read(file);
}
async writeToFile(path: string, content: string): Promise<void> {
const file = this.app.vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
await this.app.vault.modify(file, content);
} else {
await this.app.vault.create(path, content);
}
}
```
## 5. Error Handling
```typescript
import { Notice } from 'obsidian';
async performAction(): Promise<void> {
try {
const result = await this.riskyOperation();
new Notice('Success!');
} catch (error) {
console.error('Error in performAction:', error);
new Notice(`Error: ${error.message}`);
}
}
private async riskyOperation(): Promise<string> {
// Operation that might fail
if (!this.settings.apiKey) {
throw new Error('API key not configured');
}
return 'result';
}
```
## 6. Custom Types
```typescript
// Custom data structures
interface Note {
path: string;
content: string;
metadata: NoteMetadata;
}
interface NoteMetadata {
created: number;
modified: number;
tags: string[];
}
type ProcessingStatus = 'pending' | 'processing' | 'complete' | 'error';
interface ProcessingResult {
status: ProcessingStatus;
data?: any;
error?: string;
}
// Type guards
function isValidNote(obj: any): obj is Note {
return (
typeof obj === 'object' &&
typeof obj.path === 'string' &&
typeof obj.content === 'string' &&
obj.metadata !== undefined
);
}
```
## 7. Async Patterns
```typescript
// Sequential processing
async processSequentially(items: string[]): Promise<string[]> {
const results: string[] = [];
for (const item of items) {
const result = await this.processItem(item);
results.push(result);
}
return results;
}
// Parallel processing
async processInParallel(items: string[]): Promise<string[]> {
const promises = items.map(item => this.processItem(item));
return await Promise.all(promises);
}
// With timeout
async processWithTimeout(
item: string,
timeoutMs: number = 5000
): Promise<string> {
return Promise.race([
this.processItem(item),
new Promise<string>((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), timeoutMs)
)
]);
}
```
# tsconfig.json
```json
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"lib": ["DOM", "ES5", "ES6", "ES7"],
"jsx": "react"
},
"include": ["**/*.ts", "**/*.tsx"]
}
```
# Best Practices
1. Always define interfaces for settings and data structures
2. Use strict null checks
3. Prefer async/await over promises
4. Add proper error handling with try/catch
5. Use type guards for runtime type checking
6. Leverage Obsidian's built-in types from 'obsidian' package
7. Avoid 'any' type - use 'unknown' if type is truly unknown
When helping with TypeScript:
1. Identify missing or incorrect types
2. Add proper interfaces and types
3. Fix type errors
4. Improve type safety
5. Add error handling where needed
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.