1# typescript_type 2 3The `typescript_type` allows us to use typescript declarations in `typescript_custom_section` as arguments for rust functions! For example: 4 5```rust 6#[wasm_bindgen(typescript_custom_section)] 7const ITEXT_STYLE: &'static str = r#" 8interface ITextStyle { 9 bold: boolean; 10 italic: boolean; 11 size: number; 12} 13"#; 14 15#[wasm_bindgen] 16extern "C" { 17 #[wasm_bindgen(typescript_type = "ITextStyle")] 18 pub type ITextStyle; 19} 20 21#[wasm_bindgen] 22#[derive(Default)] 23pub struct TextStyle { 24 pub bold: bool, 25 pub italic: bool, 26 pub size: i32, 27} 28 29#[wasm_bindgen] 30impl TextStyle { 31 #[wasm_bindgen(constructor)] 32 pub fn new(_i: ITextStyle) -> TextStyle { 33 // parse JsValue 34 TextStyle::default() 35 } 36 37 pub fn optional_new(_i: Option<ITextStyle>) -> TextStyle { 38 // parse JsValueo 39 TextStyle::default() 40 } 41} 42``` 43 44We can write our `typescript` code like: 45 46```ts 47import { ITextStyle, TextStyle } from "./my_awesome_module"; 48 49const style: TextStyle = new TextStyle({ 50 bold: true, 51 italic: true, 52 size: 42, 53}); 54 55const optional_style: TextStyle = TextStyle.optional_new(); 56``` 57