Skip to content

Commit 84f5fe2

Browse files
committed
add: tests for typescript_type attribute
1 parent 7a7b412 commit 84f5fe2

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

crates/typescript-tests/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pub mod opt_args_and_ret;
55
pub mod optional_fields;
66
pub mod simple_fn;
77
pub mod simple_struct;
8+
pub mod typescript_type;
89
pub mod web_sys;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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();

0 commit comments

Comments
 (0)