fix: resolve TypeScript build errors introduced in c13e48a
Fixes 23 TypeScript errors in 8 files by properly handling type assertions
and template variable types:
**DataAdapter Casting Issues (8 fixes):**
- Use double assertion `as unknown as { basePath: string }` instead of
direct casting to avoid TypeScript's type overlap validation
- Files: BinaryLocator, ExportOrchestrator, PathResolver, PluginLifecycle, TemplateManager
**Template Variables Type Issues (15 fixes):**
- Add `undefined` to Record<string, string|number|boolean> union type
- Convert template variable values to appropriate types before passing to UI methods:
- String() for dropdown setValue() methods
- Number() for slider setValue() methods
- Update interface definitions in modalTypes.ts and ModalState.ts
The double assertion pattern is required because basePath exists at runtime
in Obsidian's FileSystemAdapter but isn't in the TypeScript definitions.
Adding undefined to template variables properly handles uninitialized values.
All changes maintain full functionality while ensuring type safety.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
10 files changed
+22
-22
No files matched your search
@@ -83,7 +83,7 @@ export class BinaryLocator {
|
|||||||
// Strategy 2: Assuming we're running from vault root
|
// Strategy 2: Assuming we're running from vault root
|
||||||
path.join(configDir, 'plugins', pluginDirName),
|
path.join(configDir, 'plugins', pluginDirName),
|
||||||
// Strategy 3: From vault base path if plugin is available
|
// Strategy 3: From vault base path if plugin is available
|
||||||
...(plugin ? [path.join((plugin.app.vault.adapter as { basePath: string }).basePath, plugin.manifest.dir!)] : [])
|
...(plugin ? [path.join((plugin.app.vault.adapter as unknown as { basePath: string }).basePath, plugin.manifest.dir!)] : [])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class ModalSettingsHelper {
|
|||||||
/**
|
/**
|
||||||
* Build template variables object from plugin settings
|
* Build template variables object from plugin settings
|
||||||
*/
|
*/
|
||||||
private static buildTemplateVariables(settings: obsidianTypstPDFExportSettings): Record<string, string | number | boolean> {
|
private static buildTemplateVariables(settings: obsidianTypstPDFExportSettings): Record<string, string | number | boolean | undefined> {
|
||||||
const baseVariables = {
|
const baseVariables = {
|
||||||
pageSize: settings.pageSetup.size,
|
pageSize: settings.pageSetup.size,
|
||||||
orientation: settings.pageSetup.orientation,
|
orientation: settings.pageSetup.orientation,
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export class ExportOrchestrator {
|
|||||||
* Export a file with specific configuration
|
* Export a file with specific configuration
|
||||||
*/
|
*/
|
||||||
async exportFileWithConfig(file: TFile, config: ExportConfig): Promise<void> {
|
async exportFileWithConfig(file: TFile, config: ExportConfig): Promise<void> {
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as { basePath: string }).basePath;
|
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||||
const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!);
|
const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!);
|
||||||
|
|
||||||
// Create controller for this export (allows cancellation)
|
// Create controller for this export (allows cancellation)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export class PathResolver {
|
|||||||
throw new Error(`Invalid output folder path: ${outputFolder}. Path contains invalid characters or traversal attempts.`);
|
throw new Error(`Invalid output folder path: ${outputFolder}. Path contains invalid characters or traversal attempts.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as { basePath: string }).basePath;
|
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||||
const outputDir = path.join(vaultPath, outputFolder);
|
const outputDir = path.join(vaultPath, outputFolder);
|
||||||
|
|
||||||
// Create output directory if it doesn't exist
|
// Create output directory if it doesn't exist
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class PluginLifecycle {
|
|||||||
await this.plugin.loadSettings();
|
await this.plugin.loadSettings();
|
||||||
|
|
||||||
// Initialize embedded template manager
|
// Initialize embedded template manager
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as { basePath: string }).basePath;
|
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||||
const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!);
|
const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!);
|
||||||
this.plugin.embeddedTemplateManager = new EmbeddedTemplateManager(pluginDir);
|
this.plugin.embeddedTemplateManager = new EmbeddedTemplateManager(pluginDir);
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ export class PluginLifecycle {
|
|||||||
|
|
||||||
// Clean up temp directories on plugin unload
|
// Clean up temp directories on plugin unload
|
||||||
try {
|
try {
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as { basePath: string }).basePath;
|
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||||
cleanupManager.cleanupAllTempDirs();
|
cleanupManager.cleanupAllTempDirs();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -79,7 +79,7 @@ export class PluginLifecycle {
|
|||||||
*/
|
*/
|
||||||
private cleanupStartupTempDirectories(): void {
|
private cleanupStartupTempDirectories(): void {
|
||||||
try {
|
try {
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as { basePath: string }).basePath;
|
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
||||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||||
const _result = cleanupManager.cleanupAllTempDirs();
|
const _result = cleanupManager.cleanupAllTempDirs();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class TemplateManager {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
// Templates are stored in the plugin directory
|
// Templates are stored in the plugin directory
|
||||||
this.templatesPath = path.join(
|
this.templatesPath = path.join(
|
||||||
(this.plugin.app.vault.adapter as { basePath: string }).basePath,
|
(this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath,
|
||||||
this.plugin.manifest.dir!,
|
this.plugin.manifest.dir!,
|
||||||
'templates'
|
'templates'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export interface ExportConfig {
|
|||||||
/** Override output folder */
|
/** Override output folder */
|
||||||
outputFolder?: string;
|
outputFolder?: string;
|
||||||
/** Template variables for this export */
|
/** Template variables for this export */
|
||||||
templateVariables?: Record<string, string | number | boolean>;
|
templateVariables?: Record<string, string | number | boolean | undefined>;
|
||||||
/** Open PDF after export */
|
/** Open PDF after export */
|
||||||
openAfterExport?: boolean;
|
openAfterExport?: boolean;
|
||||||
/** Preserve folder structure when exporting */
|
/** Preserve folder structure when exporting */
|
||||||
@@ -59,9 +59,9 @@ export interface ValidationResult {
|
|||||||
|
|
||||||
export interface ModalState {
|
export interface ModalState {
|
||||||
settings: ExportConfigModalSettings;
|
settings: ExportConfigModalSettings;
|
||||||
templateVariables: Record<string, string | number | boolean>;
|
templateVariables: Record<string, string | number | boolean | undefined>;
|
||||||
updateSettings(updates: Partial<ExportConfigModalSettings>): void;
|
updateSettings(updates: Partial<ExportConfigModalSettings>): void;
|
||||||
updateTemplateVariables(updates: Record<string, string | number | boolean>): void;
|
updateTemplateVariables(updates: Record<string, string | number | boolean | undefined>): void;
|
||||||
buildExportConfig(): ExportConfig;
|
buildExportConfig(): ExportConfig;
|
||||||
notifyChange(): void;
|
notifyChange(): void;
|
||||||
setProgress(percent: number, operation: string): void;
|
setProgress(percent: number, operation: string): void;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class PageSetupSection implements ModalSection {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(state.templateVariables.pageSize || 'a4')
|
.setValue(String(state.templateVariables.pageSize || 'a4'))
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ pageSize: value });
|
state.updateTemplateVariables({ pageSize: value });
|
||||||
});
|
});
|
||||||
@@ -50,7 +50,7 @@ export class PageSetupSection implements ModalSection {
|
|||||||
dropdown
|
dropdown
|
||||||
.addOption('portrait', 'Portrait')
|
.addOption('portrait', 'Portrait')
|
||||||
.addOption('landscape', 'Landscape')
|
.addOption('landscape', 'Landscape')
|
||||||
.setValue(state.templateVariables.orientation || 'portrait')
|
.setValue(String(state.templateVariables.orientation || 'portrait'))
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
const isLandscape = value === 'landscape';
|
const isLandscape = value === 'landscape';
|
||||||
state.updateTemplateVariables({
|
state.updateTemplateVariables({
|
||||||
@@ -90,7 +90,7 @@ export class PageSetupSection implements ModalSection {
|
|||||||
.addText(text => {
|
.addText(text => {
|
||||||
const input = text
|
const input = text
|
||||||
.setPlaceholder(marginDefaults[side as keyof typeof marginDefaults])
|
.setPlaceholder(marginDefaults[side as keyof typeof marginDefaults])
|
||||||
.setValue(state.templateVariables[`margin${side.charAt(0).toUpperCase() + side.slice(1)}`] || marginDefaults[side as keyof typeof marginDefaults])
|
.setValue(String(state.templateVariables[`margin${side.charAt(0).toUpperCase() + side.slice(1)}`] || marginDefaults[side as keyof typeof marginDefaults]))
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
const marginKey = `margin${side.charAt(0).toUpperCase() + side.slice(1)}`;
|
const marginKey = `margin${side.charAt(0).toUpperCase() + side.slice(1)}`;
|
||||||
state.updateTemplateVariables({ [marginKey]: value });
|
state.updateTemplateVariables({ [marginKey]: value });
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class TypographySection implements ModalSection {
|
|||||||
.setName('Body font')
|
.setName('Body font')
|
||||||
.setDesc('Primary font for document text')
|
.setDesc('Primary font for document text')
|
||||||
.addDropdown(dropdown => {
|
.addDropdown(dropdown => {
|
||||||
const currentFont = state.templateVariables.bodyFont || 'Times New Roman';
|
const currentFont = String(state.templateVariables.bodyFont || 'Times New Roman');
|
||||||
|
|
||||||
// Add all available fonts
|
// Add all available fonts
|
||||||
availableFonts.forEach(font => {
|
availableFonts.forEach(font => {
|
||||||
@@ -56,7 +56,7 @@ export class TypographySection implements ModalSection {
|
|||||||
.setName('Heading font')
|
.setName('Heading font')
|
||||||
.setDesc('Font for headings and titles')
|
.setDesc('Font for headings and titles')
|
||||||
.addDropdown(dropdown => {
|
.addDropdown(dropdown => {
|
||||||
const currentFont = state.templateVariables.headingFont || 'Times New Roman';
|
const currentFont = String(state.templateVariables.headingFont || 'Times New Roman');
|
||||||
|
|
||||||
// Add all available fonts
|
// Add all available fonts
|
||||||
availableFonts.forEach(font => {
|
availableFonts.forEach(font => {
|
||||||
@@ -81,7 +81,7 @@ export class TypographySection implements ModalSection {
|
|||||||
.setName('Monospace font')
|
.setName('Monospace font')
|
||||||
.setDesc('Font for code blocks and inline code')
|
.setDesc('Font for code blocks and inline code')
|
||||||
.addDropdown(dropdown => {
|
.addDropdown(dropdown => {
|
||||||
const currentFont = state.templateVariables.monospaceFont || 'Courier New';
|
const currentFont = String(state.templateVariables.monospaceFont || 'Courier New');
|
||||||
|
|
||||||
// Add all available fonts
|
// Add all available fonts
|
||||||
availableFonts.forEach(font => {
|
availableFonts.forEach(font => {
|
||||||
@@ -111,7 +111,7 @@ export class TypographySection implements ModalSection {
|
|||||||
.setDesc('Base font size for document text (in points)')
|
.setDesc('Base font size for document text (in points)')
|
||||||
.addSlider(slider => slider
|
.addSlider(slider => slider
|
||||||
.setLimits(8, 16, 0.5)
|
.setLimits(8, 16, 0.5)
|
||||||
.setValue(state.templateVariables.bodyFontSize || 11)
|
.setValue(Number(state.templateVariables.bodyFontSize || 11))
|
||||||
.setDynamicTooltip()
|
.setDynamicTooltip()
|
||||||
.onChange(value => {
|
.onChange(value => {
|
||||||
state.updateTemplateVariables({ bodyFontSize: value });
|
state.updateTemplateVariables({ bodyFontSize: value });
|
||||||
@@ -179,7 +179,7 @@ export class TypographySection implements ModalSection {
|
|||||||
: state.templateVariables.headingFont;
|
: state.templateVariables.headingFont;
|
||||||
|
|
||||||
dropdown
|
dropdown
|
||||||
.setValue(currentValue || 'Concourse OT')
|
.setValue(String(currentValue || 'Concourse OT'))
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
if (fontType === 'body') {
|
if (fontType === 'body') {
|
||||||
state.updateTemplateVariables({ bodyFont: value });
|
state.updateTemplateVariables({ bodyFont: value });
|
||||||
@@ -199,7 +199,7 @@ export class TypographySection implements ModalSection {
|
|||||||
.addOption('DejaVu Sans Mono', 'DejaVu Sans Mono')
|
.addOption('DejaVu Sans Mono', 'DejaVu Sans Mono')
|
||||||
.addOption('Liberation Mono', 'Liberation Mono')
|
.addOption('Liberation Mono', 'Liberation Mono')
|
||||||
.addOption('Ubuntu Mono', 'Ubuntu Mono')
|
.addOption('Ubuntu Mono', 'Ubuntu Mono')
|
||||||
.setValue(state.templateVariables.monospaceFont || 'Source Code Pro')
|
.setValue(String(state.templateVariables.monospaceFont || 'Source Code Pro'))
|
||||||
.onChange((value: string) => {
|
.onChange((value: string) => {
|
||||||
state.updateTemplateVariables({ monospaceFont: value });
|
state.updateTemplateVariables({ monospaceFont: value });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { ExportFormat, obsidianTypstPDFExportSettings } from '../../../core/sett
|
|||||||
|
|
||||||
export class ModalState implements IModalState {
|
export class ModalState implements IModalState {
|
||||||
settings: ExportConfigModalSettings;
|
settings: ExportConfigModalSettings;
|
||||||
templateVariables: Record<string, string | number | boolean>;
|
templateVariables: Record<string, string | number | boolean | undefined>;
|
||||||
|
|
||||||
private changeListeners: Set<() => void> = new Set();
|
private changeListeners: Set<() => void> = new Set();
|
||||||
private static readonly STORAGE_KEY = 'typst-export-modal-state';
|
private static readonly STORAGE_KEY = 'typst-export-modal-state';
|
||||||
@@ -64,7 +64,7 @@ export class ModalState implements IModalState {
|
|||||||
/**
|
/**
|
||||||
* Update template variables
|
* Update template variables
|
||||||
*/
|
*/
|
||||||
updateTemplateVariables(updates: Record<string, string | number | boolean>): void {
|
updateTemplateVariables(updates: Record<string, string | number | boolean | undefined>): void {
|
||||||
this.templateVariables = {
|
this.templateVariables = {
|
||||||
...this.templateVariables,
|
...this.templateVariables,
|
||||||
...updates
|
...updates
|
||||||
|
|||||||
Reference in new issue
Block a user