File tree 4 files changed +99
-1
lines changed
reference_output/test_range1
tsify-next-macros/src/typescript
4 files changed +99
-1
lines changed Original file line number Diff line number Diff line change
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {Range } _range
5
+ */
6
+ export function consume ( _range : Range ) : void ;
7
+ /**
8
+ * @returns {Range }
9
+ */
10
+ export function into_js ( ) : Range ;
11
+ /**
12
+ * @param {(Range)[] } _ranges
13
+ */
14
+ export function consume_vector ( _ranges : ( Range ) [ ] ) : void ;
15
+ /**
16
+ * @returns {(Range)[] }
17
+ */
18
+ export function vector_into_js ( ) : ( Range ) [ ] ;
19
+ export interface Range {
20
+ foo : number ;
21
+ bar : string ;
22
+ }
23
+
24
+ export interface A {
25
+ range : Range ;
26
+ }
27
+
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " test_range1"
3
+ publish = false
4
+ version = " 0.1.0"
5
+ edition = " 2021"
6
+
7
+ [dependencies ]
8
+ wasm-bindgen = " 0.2"
9
+ tsify-next = { path = " ../.." , version = " *" }
10
+ serde = { version = " 1.0" , features = [" derive" ] }
11
+ serde_json = " 1.0"
12
+
13
+ [dev-dependencies ]
14
+ wasm-bindgen-test = " 0.3"
15
+
16
+ [lib ]
17
+ path = " entry_point.rs"
18
+ crate-type = [" cdylib" ]
19
+
20
+ [build-dependencies ]
21
+ wasm-bindgen-cli = " 0.2"
Original file line number Diff line number Diff line change
1
+ use serde:: { Deserialize , Serialize } ;
2
+ use tsify_next:: Tsify ;
3
+ use wasm_bindgen:: prelude:: * ;
4
+
5
+ #[ derive( Tsify , Serialize , Deserialize ) ]
6
+ #[ tsify( into_wasm_abi, from_wasm_abi) ]
7
+ pub struct Range {
8
+ foo : u32 ,
9
+ bar : String ,
10
+ }
11
+
12
+ #[ derive( Tsify , Serialize , Deserialize ) ]
13
+ #[ tsify( into_wasm_abi, from_wasm_abi) ]
14
+ pub struct A {
15
+ range : Range ,
16
+ }
17
+
18
+ #[ wasm_bindgen]
19
+ pub fn consume ( _range : Range ) { }
20
+
21
+ #[ wasm_bindgen]
22
+ pub fn into_js ( ) -> Range {
23
+ Range {
24
+ foo : 42 ,
25
+ bar : "BAR" . to_string ( ) ,
26
+ }
27
+ }
28
+
29
+ #[ wasm_bindgen]
30
+ pub fn consume_vector ( _ranges : Vec < Range > ) { }
31
+
32
+ #[ wasm_bindgen]
33
+ pub fn vector_into_js ( ) -> Vec < Range > {
34
+ vec ! [
35
+ Range {
36
+ foo: 42 ,
37
+ bar: "BAR" . to_string( ) ,
38
+ } ,
39
+ Range {
40
+ foo: 42 ,
41
+ bar: "BAR" . to_string( ) ,
42
+ } ,
43
+ Range {
44
+ foo: 42 ,
45
+ bar: "BAR" . to_string( ) ,
46
+ } ,
47
+ ]
48
+ }
Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ impl TsType {
117
117
nanos_since_epoch: Self :: NUMBER ;
118
118
} ,
119
119
120
- "Range" | "RangeInclusive" => {
120
+ // Treat as std::ops::Range or std::ops::RangeInclusive only when there is exactly one type parameter.
121
+ // Otherwise, consider it a user-defined type and do not perform any conversion.
122
+ "Range" | "RangeInclusive" if args. len ( ) == 1 => {
121
123
let start = Self :: from_syn_type ( config, args[ 0 ] ) ;
122
124
let end = start. clone ( ) ;
123
125
You can’t perform that action at this time.
0 commit comments