Skip to content

Commit c1503f6

Browse files
committed
Improve ES6 support in TypeScript definitions generation
Users building with --emit-tsd and the EXPORT_ES6 setting should get TypeScript definitions accounting for the fact that ES6 modules include a default export that is a functor to instantiate and access the wasm module in question When generating TS definitions, query the EXPORT_ES6 setting and, if present, add the appropriate exports to the output Include options param in default functor export for `--emit-tsd`. This serves as a starting point for incluing all options such as `locateFile` (and the slew of others), without requiring manually iterating through them Update tests to include factory function
1 parent 4de9bbb commit c1503f6

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

test/other/embind_tsgen_ignore_2.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ interface EmbindModule {
109109
wstring_test(_0: string): string;
110110
}
111111
export type MainModule = WasmModule & EmbindModule;
112+
export default function MainModuleFactory (options?: unknown): Promise<MainModule>;

tools/emscripten.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ def create_tsd(metadata, embind_tsd):
631631
if embind_tsd:
632632
export_interfaces += ' & EmbindModule'
633633
out += f'export type MainModule = {export_interfaces};\n'
634+
if settings.EXPORT_ES6 and settings.MODULARIZE:
635+
out += 'export default function MainModuleFactory (options?: unknown): Promise<MainModule>;\n'
634636
return out
635637

636638

0 commit comments

Comments
 (0)