-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
map typescript default module #2064
Comments
You need to bind it like this: #[wasm_bindgen(module = "typescript")]
extern {
type Ts;
#[wasm_bindgen(js_name = default)]
static ts: Ts;
#[wasm_bindgen(method)]
fn getNodeMajorVersion(this: &Ts) -> String;
// static version: String;
} |
Hmmm, actually, after checking the generated code, that looks for a I don't think we actually have any way to bind to the actual module right now. |
However, if you only need to bind to the properties (not the module itself), you can do this: #[wasm_bindgen(module = "typescript")]
extern {
fn getNodeMajorVersion() -> String;
} That should work fine. |
I do want to build to be able to bind to the module itself, access That suggested binding leads to this error:
wasm_game_of_life.js:62 is the line with module.exports.__wbg_getNodeMajorVersion_13fd2c79e63df52c = function(arg0) {
var ret = getNodeMajorVersion();
var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
}; |
I pushed the code here: |
@ctaggart The problem with your code is that You don't need to bind to the #[wasm_bindgen(module = "typescript")]
extern {
fn getNodeMajorVersion() -> Option<u32>;
static version: String;
} |
Works great @Pauan, thanks! use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn greet() {
log("hello node");
if let Some(major_node_version) = getNodeMajorVersion() {
log(&format!("Node major version: {}", &major_node_version));
}
log(&format!("TypeScript version: {}", &version.to_string()));
}
// https://rustwasm.github.io/docs/wasm-bindgen/examples/console-log.html
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
// https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-js-imports/module.html
#[wasm_bindgen(module = "typescript")]
extern {
fn getNodeMajorVersion() -> Option<u32>;
static version: String;
} greet() prints:
|
I'm having difficulty mapping the typescript module. The generated code creates:
but I think it will work if it creates:
I found #1006 fixed by #1106, but I couldn't get it to work. Here is lib.rs:
I've tried
#[wasm_bindgen(js_name = default)]
onstatic ts: Ts
as well.The text was updated successfully, but these errors were encountered: