You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using --embind-emit-tsd should define auxiliary Webassembly-module members #20296
On the latest release of EMSDK, 3.1.46, I can now use the --embind-emit-tsd flag to generate embind TS definitions for my webassembly modules. However, naively switching to this causes some TS compiler complaints about missing members and functions, as our hand-written .d.ts files included some subset of the auxiliary EmscriptenModule definitions (basically whatever we were actually using and needed). For our projects we used a pattern looking like this:
exportinterfaceWebassemblyModule{HEAPU8: Uint8Array;_malloc(size: number): number;_free(ptr: number): void;// Other auxiliary stuff might be defined here}exportinterfaceMyModuleextendsWebassemblyModule{myBindingsGoHere(): void;}declarefunctionMyModule(options?: {locateFile(filename: string): string;}): Promise<MyModule>;exportdefaultMyModule;
In concept this can be worked around without too much effort, by emitting the embinding definitions to something like wasm.ts, then hard-coding a TS definition file like this.
Of course the downside to this is that it still has to be manually maintained, and it adds complication to builds.
If it's not a huge lift, it would be nice to include auxiliary stuff, such as things exposed by the EXPORTED_FUNCTIONS flag & whatever is always there, so users don't have to manually add them. That way, nothing needs to be manually maintained, and the d.ts file advertises (closer to) everything accessible on the module object.
Bump on this -- getting a typescript .d.ts file that fully describes the types involved when loading the compiled JS file would help this feature be used more broadly, since right now it doesn't "just work" and that's a deal breaker for many users.
@brendandahl what about stuff like MODULARIZE/EXPORT_ES6 flags? When I use those, the .d.ts output doesn't include typescript declarations for this code present in the JS output, which causes the two not to line up
Would that be better handled as a separate ticket? I can see reasonable arguments for handling here, or splitting it out, so I don't have a strong opinion
@brendandahl I took a quick stab at improving ES6 support in #21460, but I haven't contributed to Esmcripten and don't yet have a dev environment set up. I'll work on that now, but do you think you can take a quick look to let me know if, generally, the approach in the PR is sensible?
Activity
jnickg commentedon Sep 21, 2023
Including stuff listed in
INCOMING_MODULE_JS_APIwould be helpful too.jnickg commentedon Oct 24, 2023
Bump on this -- getting a typescript
.d.tsfile that fully describes the types involved when loading the compiled JS file would help this feature be used more broadly, since right now it doesn't "just work" and that's a deal breaker for many users.brendandahl commentedon Feb 6, 2024
In #21279 I've added the wasm module exports to definitions. There will still be more work needed to get the full definition though.
jnickg commentedon Mar 1, 2024
@brendandahl what about stuff like
MODULARIZE/EXPORT_ES6flags? When I use those, the.d.tsoutput doesn't include typescript declarations for this code present in the JS output, which causes the two not to line upWould that be better handled as a separate ticket? I can see reasonable arguments for handling here, or splitting it out, so I don't have a strong opinion
jnickg commentedon Mar 1, 2024
@brendandahl I took a quick stab at improving ES6 support in #21460, but I haven't contributed to Esmcripten and don't yet have a dev environment set up. I'll work on that now, but do you think you can take a quick look to let me know if, generally, the approach in the PR is sensible?