You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use wasm_bindgen::prelude::*;#[wasm_bindgen]pubstructVecU32{xs:Vec<u32>,}#[wasm_bindgen]implVecU32{pubfneach(&self,f:&js_sys::Function){let this = JsValue::null();for&x in&self.xs{let x = JsValue::from(x);let _ = f.call1(&this,&x);}}}
I'd like to type the f parameter of the each function in the d.ts file, supposedly like this:
each(f: (value: number)=>void);
The text was updated successfully, but these errors were encountered:
Yes it is, you can make a custom subclass of js_sys::Function and give it the appropriate typescript_type:
use wasm_bindgen::prelude::*;#[wasm_bindgen]extern"C"{#[wasm_bindgen(extends = js_sys::Function, typescript_type = "(value: number) => void")]pubtypeNumberFunc;}#[wasm_bindgen]pubstructVecU32{xs:Vec<u32>,}#[wasm_bindgen]implVecU32{pubfneach(&self,f:&NumberFunc){let this = JsValue::null();for&x in&self.xs{let x = JsValue::from(x);let _ = f.call1(&this,&x);}}}
The same solution works for #3107. (Well, not perfectly, the OP there asked for an attribute on the function rather than having to declare a type, but more or less.)
E.g. in the example of Receiving JavaScript Closures in Exported Rust Functions:
I'd like to type the
f
parameter of theeach
function in the d.ts file, supposedly like this:The text was updated successfully, but these errors were encountered: