Improve TypeScript types and error handling

- Created proper TypeScript types for Office API operations
- Replaced 'any' casts with appropriate types
- Added type-safe utility functions in office-types.ts
- Improved error handling with proper unknown type
- Added helper functions for PowerPoint shape operations
- Created proper TypeScript interface for webpack HMR

These changes improve code quality, maintainability, and help catch potential bugs at compile time rather than runtime.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-15 00:02:35 +01:00
parent 07b0232726
commit 50966867b2
4 changed files with 79 additions and 13 deletions
+48
View File
@@ -0,0 +1,48 @@
/**
* Type definitions for the Office JS API
*/
/**
* Extended Error interface for Office/PowerPoint API errors
*/
export interface OfficeApiError extends Error {
code?: string;
debugInfo?: {
code?: string;
message?: string;
errorLocation?: string;
statement?: string;
innerError?: any;
};
}
/**
* Helper to safely extract error message from any error object
*/
export function getErrorMessage(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
/**
* Type-safe wrapper for PowerPoint API operations on shapes
*/
export function isPictureShape(shape: PowerPoint.Shape): boolean {
return shape.type === PowerPoint.ShapeType.image;
}
/**
* Type-safe wrapper for working with PowerPoint slides
*/
export function getFirstSelectedSlide(context: PowerPoint.RequestContext): PowerPoint.Slide {
return context.presentation.getSelectedSlides().getItemAt(0);
}
/**
* Type-safe utility for selecting shapes
*/
export function selectShapesById(slide: PowerPoint.Slide, shapeIds: string[]): void {
slide.setSelectedShapes(shapeIds);
}