Skip to content

Inconsistent typescript bindings generated for fn with &mut [u8] arg #3367

Open
@cam-narzt

Description

@cam-narzt

Describe the Bug

The typescript bindings generated for the below function are inconsistent with themselves.

#[wasm_bindgen]
pub fn receive_bytes(file: &mut [u8]) -> Result<(), JsValue> {
    Ok(())
}

Steps to Reproduce

  1. Clone https://github.com/cam-narzt/rust-was-bug
  2. Run wasm-pack build --target web
  3. Run fgrep -RHie receive_ pkg
  4. See mismatched function signatures

Expected Behavior

Type signatures of functions should be consistent in exported bindings, per https://github.com/rustwasm/wasm-bindgen/blob/main/examples/without-a-bundler/index.html#L41-L43 the value returned by the init function should be the same as the exports from the module. Using the value returned by init is very preferable because then you know that you haven't introduced a race between the wasm module loading and using it's exports, but the InitOutput interface has what I assume are the internal details function's signatures.

Actual Behavior

The signature of the function is inconsistent.
If I import { receive_bytes } from 'pkg/wasm_bug'; I get function receive_bytes(file: Uint8Array): void, as expected.
If I import init, { InitOutput } from 'pkg/wasm_bug'; and use the result of init, I get receive_bytes: (a: number, b: number, c: number, d: number) => void, which seems to be some internal implementation function for converting between the js and rust types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeTracking breaking changes for the next major version bump (if ever)bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions