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