File tree 3 files changed +47
-0
lines changed
crates/typescript-tests/src
3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ pub mod opt_args_and_ret;
5
5
pub mod optional_fields;
6
6
pub mod simple_fn;
7
7
pub mod simple_struct;
8
+ pub mod typescript_type;
8
9
pub mod web_sys;
Original file line number Diff line number Diff line change
1
+ use wasm_bindgen:: prelude:: * ;
2
+
3
+ #[ wasm_bindgen( typescript_custom_section) ]
4
+ const ITEXT_STYLE : & ' static str = r#"
5
+ interface ITextStyle {
6
+ bold: boolean;
7
+ italic: boolean;
8
+ size: number;
9
+ }
10
+ "# ;
11
+
12
+ #[ wasm_bindgen]
13
+ extern "C" {
14
+ #[ wasm_bindgen( typescript_type = "ITextStyle" ) ]
15
+ pub type ITextStyle ;
16
+ }
17
+
18
+ #[ wasm_bindgen]
19
+ #[ derive( Default ) ]
20
+ pub struct TextStyle {
21
+ pub bold : bool ,
22
+ pub italic : bool ,
23
+ pub size : i32 ,
24
+ }
25
+
26
+ #[ wasm_bindgen]
27
+ impl TextStyle {
28
+ #[ wasm_bindgen( constructor) ]
29
+ pub fn new ( _i : ITextStyle ) {
30
+ // parse JsValue
31
+ }
32
+
33
+ pub fn optional_new ( _i : Option < ITextStyle > ) -> TextStyle {
34
+ // parse JsValueo
35
+ TextStyle :: default ( )
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ import * as wbg from '../pkg/typescript_tests' ;
2
+
3
+ const style : wbg . TextStyle = new wbg . TextStyle ( {
4
+ bold : true ,
5
+ italic : true ,
6
+ size : 42 ,
7
+ } ) ;
8
+
9
+ const optional_style : wbg . TextStyle = wbg . TextStyle . optional_new ( ) ;
You can’t perform that action at this time.
0 commit comments