refactor: complete TypeScript type safety improvements
- Replace all 'any' types with proper TypeScript types throughout codebase - Fix processedResult parameters to use PreprocessingResult interface - Update UI modal types: app parameter (App), pluginDefaults (obsidianTypstPDFExportSettings) - Fix dropdown components to use DropdownComponent from Obsidian API - Replace plugin 'any' types with obsidianTypstPDFExport throughout converters - Fix margins parameter to use proper interface structure - Update fs parameter to use proper Node.js fs module type - Improve error handling with proper unknown type and type guards - Remove unused PdfEmbedProcessor and clean up imports Achieves complete type safety with zero remaining 'any' types across src/ directory. Provides better IDE support, compile-time error detection, and maintainability. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
31 files changed
+204
-580
No files matched your search
@@ -3,7 +3,8 @@
|
||||
* Refactored modular version that uses section components
|
||||
*/
|
||||
|
||||
import { Modal, App, Notice } from 'obsidian';
|
||||
import { Modal, App } from 'obsidian';
|
||||
import { ExportErrorHandler } from '../../core/ExportErrorHandler';
|
||||
import { obsidianTypstPDFExport } from '../../../main';
|
||||
import { ExportConfig, ExportConfigModalSettings, ModalSection } from './modalTypes';
|
||||
import { ModalState } from './state/ModalState';
|
||||
@@ -101,7 +102,7 @@ export class ExportConfigModal extends Modal {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load templates:', error);
|
||||
new Notice(`Failed to load available templates: ${error.message}`);
|
||||
ExportErrorHandler.showTemplateError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ export class ExportConfigModal extends Modal {
|
||||
// Reload templates to update the dropdown
|
||||
this.loadAvailableTemplates();
|
||||
|
||||
new Notice('Settings reset to defaults');
|
||||
ExportErrorHandler.showSettingsReset();
|
||||
}
|
||||
|
||||
private async handleSubmit(): Promise<void> {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Type definitions for the Export Configuration Modal
|
||||
*/
|
||||
|
||||
import { TFile } from 'obsidian';
|
||||
import { ExportFormat } from '../../core/settings';
|
||||
import { TFile, App } from 'obsidian';
|
||||
import { ExportFormat, obsidianTypstPDFExportSettings } from '../../core/settings';
|
||||
|
||||
export interface ExportConfig {
|
||||
/** Override default template */
|
||||
@@ -46,7 +46,7 @@ export interface ExportConfigModalSettings extends ExportConfig {
|
||||
}
|
||||
|
||||
export interface ModalSection {
|
||||
render(containerEl: HTMLElement, state: ModalState, app?: any): void;
|
||||
render(containerEl: HTMLElement, state: ModalState, app?: App): void;
|
||||
validate?(): ValidationResult;
|
||||
getId(): string;
|
||||
}
|
||||
@@ -65,6 +65,6 @@ export interface ModalState {
|
||||
buildExportConfig(): ExportConfig;
|
||||
notifyChange(): void;
|
||||
setProgress(percent: number, operation: string): void;
|
||||
reset(pluginDefaults: any): void;
|
||||
reset(pluginDefaults: obsidianTypstPDFExportSettings): void;
|
||||
onChange(listener: () => void): void;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* Handles template selection, format options, and output settings
|
||||
*/
|
||||
|
||||
import { Setting, App, normalizePath } from 'obsidian';
|
||||
import { Setting, App, normalizePath, DropdownComponent } from 'obsidian';
|
||||
import { ModalSection, ModalState, ValidationResult } from '../modalTypes';
|
||||
import { ExportFormat } from '../../../core/settings';
|
||||
import { FolderSuggest } from '../../components/FolderSuggest';
|
||||
@@ -11,7 +11,7 @@ import { SecurityUtils } from '../../../core/SecurityUtils';
|
||||
|
||||
export class GeneralSection implements ModalSection {
|
||||
private container: HTMLElement | null = null;
|
||||
private templateDropdown: any = null;
|
||||
private templateDropdown: DropdownComponent | null = null;
|
||||
private outputFolderInput: HTMLInputElement | null = null;
|
||||
private app: App;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Handles font selection and size configuration
|
||||
*/
|
||||
|
||||
import { Setting, App } from 'obsidian';
|
||||
import { Setting, App, DropdownComponent } from 'obsidian';
|
||||
import { ModalSection, ModalState, ValidationResult } from '../modalTypes';
|
||||
|
||||
export class TypographySection implements ModalSection {
|
||||
@@ -161,7 +161,7 @@ export class TypographySection implements ModalSection {
|
||||
}
|
||||
}
|
||||
|
||||
private addFallbackBodyFonts(dropdown: any, state: ModalState, fontType: 'body' | 'heading'): void {
|
||||
private addFallbackBodyFonts(dropdown: DropdownComponent, state: ModalState, fontType: 'body' | 'heading'): void {
|
||||
dropdown
|
||||
.addOption('Concourse OT', 'Concourse OT')
|
||||
.addOption('Times New Roman', 'Times New Roman')
|
||||
@@ -189,7 +189,7 @@ export class TypographySection implements ModalSection {
|
||||
});
|
||||
}
|
||||
|
||||
private addFallbackMonospaceFonts(dropdown: any, state: ModalState): void {
|
||||
private addFallbackMonospaceFonts(dropdown: DropdownComponent, state: ModalState): void {
|
||||
dropdown
|
||||
.addOption('Source Code Pro', 'Source Code Pro')
|
||||
.addOption('Courier New', 'Courier New')
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { ExportConfigModalSettings, ExportConfig, ModalState as IModalState } from '../modalTypes';
|
||||
import { ExportFormat } from '../../../core/settings';
|
||||
import { ExportFormat, obsidianTypstPDFExportSettings } from '../../../core/settings';
|
||||
|
||||
export class ModalState implements IModalState {
|
||||
settings: ExportConfigModalSettings;
|
||||
@@ -138,7 +138,7 @@ export class ModalState implements IModalState {
|
||||
/**
|
||||
* Reset state to defaults
|
||||
*/
|
||||
reset(pluginDefaults: any): void {
|
||||
reset(pluginDefaults: obsidianTypstPDFExportSettings): void {
|
||||
// Reset to plugin defaults, not hardcoded defaults
|
||||
this.settings = {
|
||||
...this.settings,
|
||||
|
||||
Reference in new issue
Block a user