@@ -22,7 +22,7 @@ export function isHEICFile(file: File): boolean {
2222
2323 // Check file extension as fallback
2424 const fileName = file . name . toLowerCase ( )
25- return heicExtensions . some ( ext => fileName . endsWith ( ext ) )
25+ return heicExtensions . some ( ( ext ) => fileName . endsWith ( ext ) )
2626}
2727
2828/**
@@ -45,14 +45,18 @@ export async function convertHEIC(
4545 const { toType = 'image/jpeg' , quality = 0.92 } = options
4646
4747 // Dynamic import to make heic2any optional
48- let heic2any : any
48+ type Heic2AnyFunction = ( options : {
49+ blob : Blob
50+ toType : string
51+ quality : number
52+ } ) => Promise < Blob | Blob [ ] >
53+
54+ let heic2any : Heic2AnyFunction
4955 try {
50- heic2any = await import ( 'heic2any' )
51- heic2any = heic2any . default || heic2any
56+ const module = await import ( 'heic2any' )
57+ heic2any = ( module . default || module ) as Heic2AnyFunction
5258 } catch ( error ) {
53- throw new Error (
54- 'heic2any is not installed. To enable HEIC support, run: npm install heic2any'
55- )
59+ throw new Error ( 'heic2any is not installed. To enable HEIC support, run: npm install heic2any' )
5660 }
5761
5862 try {
@@ -63,7 +67,14 @@ export async function convertHEIC(
6367 } )
6468
6569 // heic2any can return Blob or Blob[]
66- return Array . isArray ( result ) ? result [ 0 ] : result
70+ if ( Array . isArray ( result ) ) {
71+ const firstBlob = result [ 0 ]
72+ if ( ! firstBlob ) {
73+ throw new Error ( 'heic2any returned empty array' )
74+ }
75+ return firstBlob
76+ }
77+ return result
6778 } catch ( error ) {
6879 throw new Error (
6980 `Failed to convert HEIC image: ${ error instanceof Error ? error . message : 'Unknown error' } `
0 commit comments