We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When using the js_name on an enum, a method does not get exported.
js_name
enum
Consider this snippet:
#[wasm_bindgen(js_name = Data)] pub struct JsData(u8); #[wasm_bindgen] impl JsData { #[wasm_bindgen(js_name = toString)] pub fn to_string(&self) -> String { self.0.to_string() } }
Compiled with wasm-pack build --dev --target=web.
wasm-pack build --dev --target=web
The Data class to include the toString method.
Data
toString
// In the `.d.ts` file export class Data { free(): void; /** * @returns {string} */ toString(): string; }
// In the `.d.ts` file export class Data { free(): void; }
When the js_name attribute is not used, e.g.:
-#[wasm_bindgen(js_name = Data)] +#[wasm_bindgen()] pub struct JsData(u8);
The .d.ts file will include the method:
.d.ts
export class JsData { free(): void; /** * @returns {string} */ toString(): string; }
The text was updated successfully, but these errors were encountered:
I think you can use js_class to fix this.
js_class
That said, wasm bindgen should still be better here IMO.
Sorry, something went wrong.
I tried adding it both to the method and struct:
warning: unused variable: `js_class`
But I forgot trying to add it to the impl, that works!
impl
So, in short, this works:
#[wasm_bindgen(js_name = Data)] pub struct JsData(u8); #[wasm_bindgen(js_class = Data)] impl JsData { #[wasm_bindgen(js_name = toString)] pub fn to_string(&self) -> String { self.0.to_string() } }
No branches or pull requests
Describe the Bug
When using the
js_name
on anenum
, a method does not get exported.Steps to Reproduce
Consider this snippet:
Compiled with
wasm-pack build --dev --target=web
.Expected Behavior
The
Data
class to include thetoString
method.Actual Behavior
Additional Context
When the
js_name
attribute is not used, e.g.:The
.d.ts
file will include the method:The text was updated successfully, but these errors were encountered: