Use Tsify with wasm-bindgen to generate TypeScript definitions
mainTsify integrates with wasm-bindgen to automatically output .d.ts files. Instead of using deprecated attributes like into_wasm_abi, use the Ts<T> wrapper for function parameters and return types. This allows you to convert between Rust and JS using .into_ts() and .to_rust().
use serde::{Deserialize, Serialize};
use tsify::Tsify;
use tsify::Ts;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsError;
#[derive(Tsify, Serialize, Deserialize)]
pub struct Point {
x: i32,
y: i32,
}
#[wasm_bindgen]
pub fn into_js() -> Result<Ts<Point>, JsError> {
let point = Point { x: 0, y: 0 };
Ok(point.into_ts()?.into())
}
#[wasm_bindgen]
pub fn from_js(point: Ts<Point>) -> Result<(), JsError> {
let point: Point = point.to_rust()?;
Ok(())
}