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
@@ -13,7 +13,7 @@ export interface ExportConfig {
|
||||
/** Override output folder */
|
||||
outputFolder?: string;
|
||||
/** Template variables for this export */
|
||||
templateVariables?: Record<string, string | number | boolean>;
|
||||
templateVariables?: Record<string, string | number | boolean | undefined>;
|
||||
/** Open PDF after export */
|
||||
openAfterExport?: boolean;
|
||||
/** Preserve folder structure when exporting */
|
||||
@@ -59,9 +59,9 @@ export interface ValidationResult {
|
||||
|
||||
export interface ModalState {
|
||||
settings: ExportConfigModalSettings;
|
||||
templateVariables: Record<string, string | number | boolean>;
|
||||
templateVariables: Record<string, string | number | boolean | undefined>;
|
||||
updateSettings(updates: Partial<ExportConfigModalSettings>): void;
|
||||
updateTemplateVariables(updates: Record<string, string | number | boolean>): void;
|
||||
updateTemplateVariables(updates: Record<string, string | number | boolean | undefined>): void;
|
||||
buildExportConfig(): ExportConfig;
|
||||
notifyChange(): void;
|
||||
setProgress(percent: number, operation: string): void;
|
||||
|
||||
@@ -33,7 +33,7 @@ export class PageSetupSection implements ModalSection {
|
||||
});
|
||||
|
||||
dropdown
|
||||
.setValue(state.templateVariables.pageSize || 'a4')
|
||||
.setValue(String(state.templateVariables.pageSize || 'a4'))
|
||||
.onChange(value => {
|
||||
state.updateTemplateVariables({ pageSize: value });
|
||||
});
|
||||
@@ -50,7 +50,7 @@ export class PageSetupSection implements ModalSection {
|
||||
dropdown
|
||||
.addOption('portrait', 'Portrait')
|
||||
.addOption('landscape', 'Landscape')
|
||||
.setValue(state.templateVariables.orientation || 'portrait')
|
||||
.setValue(String(state.templateVariables.orientation || 'portrait'))
|
||||
.onChange(value => {
|
||||
const isLandscape = value === 'landscape';
|
||||
state.updateTemplateVariables({
|
||||
@@ -90,7 +90,7 @@ export class PageSetupSection implements ModalSection {
|
||||
.addText(text => {
|
||||
const input = text
|
||||
.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 => {
|
||||
const marginKey = `margin${side.charAt(0).toUpperCase() + side.slice(1)}`;
|
||||
state.updateTemplateVariables({ [marginKey]: value });
|
||||
|
||||
@@ -31,7 +31,7 @@ export class TypographySection implements ModalSection {
|
||||
.setName('Body font')
|
||||
.setDesc('Primary font for document text')
|
||||
.addDropdown(dropdown => {
|
||||
const currentFont = state.templateVariables.bodyFont || 'Times New Roman';
|
||||
const currentFont = String(state.templateVariables.bodyFont || 'Times New Roman');
|
||||
|
||||
// Add all available fonts
|
||||
availableFonts.forEach(font => {
|
||||
@@ -56,7 +56,7 @@ export class TypographySection implements ModalSection {
|
||||
.setName('Heading font')
|
||||
.setDesc('Font for headings and titles')
|
||||
.addDropdown(dropdown => {
|
||||
const currentFont = state.templateVariables.headingFont || 'Times New Roman';
|
||||
const currentFont = String(state.templateVariables.headingFont || 'Times New Roman');
|
||||
|
||||
// Add all available fonts
|
||||
availableFonts.forEach(font => {
|
||||
@@ -81,7 +81,7 @@ export class TypographySection implements ModalSection {
|
||||
.setName('Monospace font')
|
||||
.setDesc('Font for code blocks and inline code')
|
||||
.addDropdown(dropdown => {
|
||||
const currentFont = state.templateVariables.monospaceFont || 'Courier New';
|
||||
const currentFont = String(state.templateVariables.monospaceFont || 'Courier New');
|
||||
|
||||
// Add all available fonts
|
||||
availableFonts.forEach(font => {
|
||||
@@ -111,7 +111,7 @@ export class TypographySection implements ModalSection {
|
||||
.setDesc('Base font size for document text (in points)')
|
||||
.addSlider(slider => slider
|
||||
.setLimits(8, 16, 0.5)
|
||||
.setValue(state.templateVariables.bodyFontSize || 11)
|
||||
.setValue(Number(state.templateVariables.bodyFontSize || 11))
|
||||
.setDynamicTooltip()
|
||||
.onChange(value => {
|
||||
state.updateTemplateVariables({ bodyFontSize: value });
|
||||
@@ -179,7 +179,7 @@ export class TypographySection implements ModalSection {
|
||||
: state.templateVariables.headingFont;
|
||||
|
||||
dropdown
|
||||
.setValue(currentValue || 'Concourse OT')
|
||||
.setValue(String(currentValue || 'Concourse OT'))
|
||||
.onChange((value: string) => {
|
||||
if (fontType === 'body') {
|
||||
state.updateTemplateVariables({ bodyFont: value });
|
||||
@@ -199,7 +199,7 @@ export class TypographySection implements ModalSection {
|
||||
.addOption('DejaVu Sans Mono', 'DejaVu Sans Mono')
|
||||
.addOption('Liberation Mono', 'Liberation Mono')
|
||||
.addOption('Ubuntu Mono', 'Ubuntu Mono')
|
||||
.setValue(state.templateVariables.monospaceFont || 'Source Code Pro')
|
||||
.setValue(String(state.templateVariables.monospaceFont || 'Source Code Pro'))
|
||||
.onChange((value: string) => {
|
||||
state.updateTemplateVariables({ monospaceFont: value });
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ExportFormat, obsidianTypstPDFExportSettings } from '../../../core/sett
|
||||
|
||||
export class ModalState implements IModalState {
|
||||
settings: ExportConfigModalSettings;
|
||||
templateVariables: Record<string, string | number | boolean>;
|
||||
templateVariables: Record<string, string | number | boolean | undefined>;
|
||||
|
||||
private changeListeners: Set<() => void> = new Set();
|
||||
private static readonly STORAGE_KEY = 'typst-export-modal-state';
|
||||
@@ -64,7 +64,7 @@ export class ModalState implements IModalState {
|
||||
/**
|
||||
* Update template variables
|
||||
*/
|
||||
updateTemplateVariables(updates: Record<string, string | number | boolean>): void {
|
||||
updateTemplateVariables(updates: Record<string, string | number | boolean | undefined>): void {
|
||||
this.templateVariables = {
|
||||
...this.templateVariables,
|
||||
...updates
|
||||
|
||||
Reference in new issue
Block a user