diff --git a/tests-e2e/reference_output/test_range1/test_range1.d.ts b/tests-e2e/reference_output/test_range1/test_range1.d.ts new file mode 100644 index 0000000..9a0c592 --- /dev/null +++ b/tests-e2e/reference_output/test_range1/test_range1.d.ts @@ -0,0 +1,27 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * @param {Range} _range + */ +export function consume(_range: Range): void; +/** + * @returns {Range} + */ +export function into_js(): Range; +/** + * @param {(Range)[]} _ranges + */ +export function consume_vector(_ranges: (Range)[]): void; +/** + * @returns {(Range)[]} + */ +export function vector_into_js(): (Range)[]; +export interface Range { + foo: number; + bar: string; +} + +export interface A { + range: Range; +} + diff --git a/tests-e2e/test_range1/Cargo.toml b/tests-e2e/test_range1/Cargo.toml new file mode 100644 index 0000000..6a7063f --- /dev/null +++ b/tests-e2e/test_range1/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "test_range1" +publish = false +version = "0.1.0" +edition = "2021" + +[dependencies] +wasm-bindgen = "0.2" +tsify-next = { path = "../..", version = "*" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" + +[dev-dependencies] +wasm-bindgen-test = "0.3" + +[lib] +path = "entry_point.rs" +crate-type = ["cdylib"] + +[build-dependencies] +wasm-bindgen-cli = "0.2" diff --git a/tests-e2e/test_range1/entry_point.rs b/tests-e2e/test_range1/entry_point.rs new file mode 100644 index 0000000..32b623c --- /dev/null +++ b/tests-e2e/test_range1/entry_point.rs @@ -0,0 +1,48 @@ +use serde::{Deserialize, Serialize}; +use tsify_next::Tsify; +use wasm_bindgen::prelude::*; + +#[derive(Tsify, Serialize, Deserialize)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Range { + foo: u32, + bar: String, +} + +#[derive(Tsify, Serialize, Deserialize)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct A { + range: Range, +} + +#[wasm_bindgen] +pub fn consume(_range: Range) {} + +#[wasm_bindgen] +pub fn into_js() -> Range { + Range { + foo: 42, + bar: "BAR".to_string(), + } +} + +#[wasm_bindgen] +pub fn consume_vector(_ranges: Vec) {} + +#[wasm_bindgen] +pub fn vector_into_js() -> Vec { + vec![ + Range { + foo: 42, + bar: "BAR".to_string(), + }, + Range { + foo: 42, + bar: "BAR".to_string(), + }, + Range { + foo: 42, + bar: "BAR".to_string(), + }, + ] +} diff --git a/tsify-next-macros/src/typescript/ts_type_from_name.rs b/tsify-next-macros/src/typescript/ts_type_from_name.rs index fa68a73..ed22474 100644 --- a/tsify-next-macros/src/typescript/ts_type_from_name.rs +++ b/tsify-next-macros/src/typescript/ts_type_from_name.rs @@ -117,7 +117,9 @@ impl TsType { nanos_since_epoch: Self::NUMBER; }, - "Range" | "RangeInclusive" => { + // Treat as std::ops::Range or std::ops::RangeInclusive only when there is exactly one type parameter. + // Otherwise, consider it a user-defined type and do not perform any conversion. + "Range" | "RangeInclusive" if args.len() == 1 => { let start = Self::from_syn_type(config, args[0]); let end = start.clone();