JsValue into Rust wasm_bindgen type

Suppose we have:

#[wasm_bindgen]
extern "C" {
    type Bar;
}
pub fn (x: JsValue) {
  let r: JsValue = js_sys::Reflect::get(x, &"foo".into()).unwrap();
}

Now, I know that r is an object of type Bar (as defined above). How do I convert this r into a Bar ?

Use JsCast::unchecked_into().

2 Likes