Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript module declaration and webpack 5 #2117

Open
BenoitDel opened this issue Apr 29, 2020 · 3 comments
Open

typescript module declaration and webpack 5 #2117

BenoitDel opened this issue Apr 29, 2020 · 3 comments
Labels

Comments

@BenoitDel
Copy link

Describe the Bug

The .d.ts are invalid with webpack 5 wasm module import. The interface exposed from the wasm import is the one from the helper.js

If i take the hello_world example from wasm_bindgen guide. hello_world_bg.d.ts generated is:

export const memory: WebAssembly.Memory;
export function greet(a: number, b: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;

and it should be this

export function greet(name: string): void;
I think

Expected behavior:

The module declaration should be modify to support webpack 5 new import when stable
Thx

@BenoitDel
Copy link
Author

trying to make a clearer explanation of my problem, when you do:
import { greet } from "./hello_world_bg.wasm"
with webpack 4, the signature should be: greet(a: number, b: number): void ? (not verified)
with webpack 5, the signature is greet(string): void. (verified)

So, the hello_world_bg.d.ts which is currently generated is incorrect. For me, it should be:
hello_world_bg.d.ts
export function greet(name: string): void;

instead of (current implementation):
hello_world_bg.d.ts

export const memory: WebAssembly.Memory;
export function greet(a: number, b: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;

@Pauan
Copy link
Contributor

Pauan commented Apr 30, 2020

@BenoitDel You are not supposed to import the hello_world_bg.wasm file, you are supposed to import hello_world.js (which does have the correct .d.ts).

@BenoitDel
Copy link
Author

@Pauan The problem has been fixed with the new wasm-bindgen version (0.2.61).
I tested it only with hello_world example. I will test the new version with more complex examples.thx

for version <=0.2.60, it was necessary to import from wasm file to have access to the helper functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants