-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support for methods ? #40
Comments
I believe |
I find tsify exporting types better than wasm_bindgen, for example in the following rust code : use crate::models::PaymentMethod;
use serde::{Serialize, Deserialize, Deserializer};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
pub fn parse_payment_methods<'de, D>(deserializer: D) -> Result<Vec<PaymentMethod>, D::Error>
where
D: Deserializer<'de>,
{
let s = Vec::<serde_json::Value>::deserialize(deserializer)?;
Ok(
s.iter()
.map(|v| PaymentMethod::from_api(v["name"].as_str().unwrap()))
.collect(),
)
}
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(getter_with_clone))]
pub struct Restaurant {
// ...
#[serde(
rename(deserialize = "payment"),
deserialize_with = "parse_payment_methods"
)]
pub payment_methods: Vec<PaymentMethod>,
// ...
} I get this .d.ts output : export class Restaurant {
// ...
payment_methods: any[];
// ...
} Every other properties are correct except this one and there's no reason why. I tried to run the exact same code with Also I like the fact that you can |
It does, usually, but it does not for structs that are tsified. For example, the following pure wasm_bindgen approach leads to what you'd expect: #[wasm_bindgen]
pub struct Foo {}
#[wasm_bindgen]
impl Foo {
pub fn foo(&self) -> JsString {
todo!()
}
} export class Foo {
free(): void;
/**
* @returns {string}
*/
bar(): string;
} But the equivalent using Tsify does not: #[derive(Tsify, Serialize, Deserialize)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Bar {}
#[wasm_bindgen]
impl Bar {
pub fn bar(&self) -> JsString {
todo!()
}
} export interface Bar {} |
Exactly the same issue as in madonoharu#39. Will this fork support it ?
The text was updated successfully, but these errors were encountered: