@@ -461,7 +461,13 @@ impl<'a> Context<'a> {
461
461
Ok ( imports)
462
462
}
463
463
464
- fn ts_for_init_fn ( has_memory : bool , has_module_or_path_optional : bool ) -> String {
464
+ fn ts_for_init_fn (
465
+ & self ,
466
+ has_memory : bool ,
467
+ has_module_or_path_optional : bool ,
468
+ ) -> Result < String , Error > {
469
+ let output = crate :: wasm2es6js:: interface ( & self . module ) ?;
470
+
465
471
let ( memory_doc, memory_param) = if has_memory {
466
472
(
467
473
"* @param {WebAssembly.Memory} maybe_memory\n " ,
@@ -471,22 +477,28 @@ impl<'a> Context<'a> {
471
477
( "" , "" )
472
478
} ;
473
479
let arg_optional = if has_module_or_path_optional { "?" } else { "" } ;
474
- format ! (
480
+ Ok ( format ! (
475
481
"\n \
482
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;\n \
483
+ \n \
484
+ export interface InitOutput {{\n \
485
+ {output}}}\n \
486
+ \n \
476
487
/**\n \
477
- * If `module_or_path` is {{RequestInfo}}, makes a request and\n \
488
+ * If `module_or_path` is {{RequestInfo}} or {{URL}} , makes a request and\n \
478
489
* for everything else, calls `WebAssembly.instantiate` directly.\n \
479
490
*\n \
480
- * @param {{RequestInfo | BufferSource | WebAssembly.Module }} module_or_path\n \
491
+ * @param {{InitInput | Promise<InitInput> }} module_or_path\n \
481
492
{}\
482
493
*\n \
483
- * @returns {{Promise<any >}}\n \
494
+ * @returns {{Promise<InitOutput >}}\n \
484
495
*/\n \
485
496
export default function init \
486
- (module_or_path{}: RequestInfo | BufferSource | WebAssembly.Module {}): Promise<any >;
497
+ (module_or_path{}: InitInput | Promise<InitInput> {}): Promise<InitOutput >;
487
498
" ,
488
- memory_doc, arg_optional, memory_param
489
- )
499
+ memory_doc, arg_optional, memory_param,
500
+ output = output,
501
+ ) )
490
502
}
491
503
492
504
fn gen_init (
@@ -541,7 +553,7 @@ impl<'a> Context<'a> {
541
553
_ => "" ,
542
554
} ;
543
555
544
- let ts = Self :: ts_for_init_fn ( has_memory, !default_module_path. is_empty ( ) ) ;
556
+ let ts = self . ts_for_init_fn ( has_memory, !default_module_path. is_empty ( ) ) ? ;
545
557
546
558
// Initialize the `imports` object for all import definitions that we're
547
559
// directed to wire up.
0 commit comments