This is the unpublished documentation of wasm-bindgen, the published documentation is available on the main Rust and WebAssembly documentation site . Features documented here may not be available in released versions of wasm-bindgen.


The typescript_type allows us to use typescript declarations in typescript_custom_section as arguments for rust functions! For example:

# #![allow(unused_variables)]
#fn main() {
const ITEXT_STYLE: &'static str = r#"
interface ITextStyle {
    bold: boolean;
    italic: boolean;
    size: number;

extern "C" {
    #[wasm_bindgen(typescript_type = "ITextStyle")]
    pub type ITextStyle;

pub struct TextStyle {
    pub bold: bool,
    pub italic: bool,
    pub size: i32,

impl TextStyle {
    pub fn new(_i: ITextStyle) -> TextStyle {
        // parse JsValue

    pub fn optional_new(_i: Option<ITextStyle>) -> TextStyle {
        // parse JsValueo

We can write our typescript code like:

import { ITextStyle, TextStyle } from "./my_awesome_module";

const style: TextStyle = new TextStyle({
  bold: true,
  italic: true,
  size: 42,

const optional_style: TextStyle = TextStyle.optional_new();