diff --git a/src/typescript.rs b/src/typescript.rs index c4ebf38..427f645 100644 --- a/src/typescript.rs +++ b/src/typescript.rs @@ -77,6 +77,18 @@ fn try_match_with_args(ident: &str, args: &syn::PathArguments) -> Result "unknown".to_owned(), }, }), + "Box" => Ok(TsType { + is_optional: false, + ts_type: match &args { + syn::PathArguments::Parenthesized(parenthesized_argument) => { + format!("{:?}", parenthesized_argument) + } + syn::PathArguments::AngleBracketed(angle_bracketed_argument) => { + convert_generic(angle_bracketed_argument.args.first().unwrap()).ts_type + } + _ => "unknown".to_owned(), + }, + }), "Vec" => Ok(match &args { syn::PathArguments::Parenthesized(parenthesized_argument) => { format!("{:?}", parenthesized_argument).into() @@ -196,6 +208,7 @@ pub fn convert_type(ty: &syn::Type) -> TsType { is_optional: false, } } + _ => "unknown".to_owned().into(), } } diff --git a/test/issue-63/rust.rs b/test/issue-63/rust.rs new file mode 100644 index 0000000..5f3b5dd --- /dev/null +++ b/test/issue-63/rust.rs @@ -0,0 +1,13 @@ +#[tsync] +struct TestStruct { + size: Box, +} + +#[tsync] +const v: Box = 23; + +#[tsync] +struct TestStruct2 { + inner: Box, + inner_unboxed: TestStruct, +} diff --git a/test/issue-63/tsync.sh b/test/issue-63/tsync.sh new file mode 100755 index 0000000..1764bd6 --- /dev/null +++ b/test/issue-63/tsync.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo run -- -i rust.rs -o typescript.d.ts +cargo run -- -i rust.rs -o typescript.ts \ No newline at end of file diff --git a/test/issue-63/typescript.d.ts b/test/issue-63/typescript.d.ts new file mode 100644 index 0000000..b85dfdd --- /dev/null +++ b/test/issue-63/typescript.d.ts @@ -0,0 +1,10 @@ +/* This file is generated and managed by tsync */ + +interface TestStruct { + size: number; +} + +interface TestStruct2 { + inner: TestStruct; + inner_unboxed: TestStruct; +} diff --git a/test/issue-63/typescript.ts b/test/issue-63/typescript.ts new file mode 100644 index 0000000..75f58e1 --- /dev/null +++ b/test/issue-63/typescript.ts @@ -0,0 +1,12 @@ +/* This file is generated and managed by tsync */ + +export interface TestStruct { + size: number; +} + +export const v = 23; + +export interface TestStruct2 { + inner: TestStruct; + inner_unboxed: TestStruct; +} diff --git a/test/test_all.sh b/test/test_all.sh index fa9feb8..ab4571b 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -17,5 +17,6 @@ cd $SCRIPT_DIR ./issue-43/tsync.sh ./issue-55/tsync.sh ./issue-58/tsync.sh +./issue-63/tsync.sh ./issue-65-untagged-enums/tsync.sh ./raw_identifiers/tsync.sh