-
-
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
Getter and Setter types #2869
Comments
Is there a reason you have |
@trevyn I do have to skip since the type there since We managed to find a way around it by doing the following(though it still feels like this process could be improved): use indexmap::IndexMap;
use serde_json::Value;
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
#[wasm_bindgen(typescript_custom_section)]
const METADATA_TYPE: &'static str = r#"
export type JSMetadata = {
[key in string]: any
};
"#;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "JSMetadata")]
pub type Test3;
}
#[wasm_bindgen(getter_with_clone)]
pub struct Tester {
pub test1: String,
pub test2: u32,
#[wasm_bindgen(skip, typescript_type = "JSMetadata")]
pub test3: IndexMap<String, Value>,
}
#[wasm_bindgen]
impl Tester {
#[wasm_bindgen(catch, constructor, js_class = "Tester")]
pub fn new(test1: String, test2: u32, test3: Option<Test3>) -> Self {
Self {
test1,
test2,
test3: if let Some(t) = test3 {
t.into_serde().unwrap()
} else {
Default::default()
},
}
}
#[wasm_bindgen(getter = test3, typescript_type = "JSMetadata")]
pub fn test3(&self) -> JsValue {
JsValue::from_serde(&self.test3).unwrap()
}
#[wasm_bindgen(setter = test3, typescript_type = "JSMetadata")]
pub fn set_test3(&mut self, field: Test3) {
self.test3 = field.into_serde().unwrap()
}
} Not sure if doing |
Hi all we are trying to set proper types on getter and setters rather than it just showing as
any
from typescript on the fieldtest3
.However, we can find very little documentation on how this crate actually works despite the guidebook.
The code is as follows:
How do we specify that for the field
test3
it should be of typeJSMetadata
as we defined above?The text was updated successfully, but these errors were encountered: