mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
add: tests for typescript_type attribute
This commit is contained in:
parent
7a7b412bae
commit
84f5fe2c00
@ -5,4 +5,5 @@ pub mod opt_args_and_ret;
|
||||
pub mod optional_fields;
|
||||
pub mod simple_fn;
|
||||
pub mod simple_struct;
|
||||
pub mod typescript_type;
|
||||
pub mod web_sys;
|
||||
|
37
crates/typescript-tests/src/typescript_type.rs
Normal file
37
crates/typescript-tests/src/typescript_type.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(typescript_custom_section)]
|
||||
const ITEXT_STYLE: &'static str = r#"
|
||||
interface ITextStyle {
|
||||
bold: boolean;
|
||||
italic: boolean;
|
||||
size: number;
|
||||
}
|
||||
"#;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(typescript_type = "ITextStyle")]
|
||||
pub type ITextStyle;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Default)]
|
||||
pub struct TextStyle {
|
||||
pub bold: bool,
|
||||
pub italic: bool,
|
||||
pub size: i32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl TextStyle {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(_i: ITextStyle) {
|
||||
// parse JsValue
|
||||
}
|
||||
|
||||
pub fn optional_new(_i: Option<ITextStyle>) -> TextStyle {
|
||||
// parse JsValueo
|
||||
TextStyle::default()
|
||||
}
|
||||
}
|
9
crates/typescript-tests/src/typescript_type.ts
Normal file
9
crates/typescript-tests/src/typescript_type.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import * as wbg from '../pkg/typescript_tests';
|
||||
|
||||
const style: wbg.TextStyle = new wbg.TextStyle({
|
||||
bold: true,
|
||||
italic: true,
|
||||
size: 42,
|
||||
});
|
||||
|
||||
const optional_style: wbg.TextStyle = wbg.TextStyle.optional_new();
|
Loading…
x
Reference in New Issue
Block a user