@@ -169,44 +169,45 @@ declare namespace JSZip {
169169 createFolders ?: boolean ;
170170 decodeFileName ?: ( bytes : string [ ] | Uint8Array | Buffer ) => string ;
171171 }
172- }
173172
174- declare namespace StreamHelper {
175- type DataEventCallback = ( dataChunk : any , metadata : any ) => any
176- type EndEventCallback = ( ) => any
177- type ErrorEventCallback = ( error : Error ) => any
173+ interface JSZipMetadata {
174+ percent : number ;
175+ currentFile : string ;
176+ }
177+
178+ type DataEventCallback < T > = ( dataChunk : T , metadata : JSZipMetadata ) => void
179+ type EndEventCallback = ( ) => void
180+ type ErrorEventCallback = ( error : Error ) => void
178181
179- interface StreamHelper {
182+ interface JSZipStreamHelper < T > {
180183 /**
181184 * Register a listener on an event
182- *
183- * @param event The name of the event. Only 3 events are supported : data, end and error
184- * @param callback The function called when the event occurs
185- * @return The current StreamHelper object, for chaining
186185 */
187- on ( event : 'data' | 'end' | 'error' , callback : DataEventCallback | EndEventCallback | ErrorEventCallback ) ;
186+ on ( event : 'data' , callback : DataEventCallback < T > ) : this;
187+ on ( event : 'end' , callback : EndEventCallback ) : this;
188+ on ( event : 'error' , callback : ErrorEventCallback ) : this;
188189
189190 /**
190191 * Read the whole stream and call a callback with the complete content
191192 *
192193 * @param updateCallback The function called every time the stream updates
193194 * @return A Promise of the full content
194195 */
195- accumulate ( updateCallback ?: ( metadata : any ) => any ) : Promise < any > ;
196+ accumulate ( updateCallback ?: ( metadata : JSZipMetadata ) => void ) : Promise < T > ;
196197
197198 /**
198199 * Resume the stream if the stream is paused. Once resumed, the stream starts sending data events again
199200 *
200201 * @return The current StreamHelper object, for chaining
201202 */
202- resume ( ) : StreamHelper ;
203+ resume ( ) : this ;
203204
204205 /**
205206 * Pause the stream if the stream is running. Once paused, the stream stops sending data events
206207 *
207208 * @return The current StreamHelper object, for chaining
208209 */
209- pause ( ) : StreamHelper ;
210+ pause ( ) : this ;
210211 }
211212}
212213
@@ -303,7 +304,7 @@ interface JSZip {
303304 * @param options Optional options for the generator
304305 * @return a StreamHelper
305306 */
306- generateInternalStream ( options ?: JSZip . JSZipGeneratorOptions ) : StreamHelper . StreamHelper
307+ generateInternalStream < T extends JSZip . OutputType > ( options ?: JSZip . JSZipGeneratorOptions < T > ) : JSZip . JSZipStreamHelper < OutputByType [ T ] > ;
307308
308309 /**
309310 * Deserialize zip file asynchronously
0 commit comments