diff --git a/src/to_typescript/structs.rs b/src/to_typescript/structs.rs index c8bd9e7..7b432ad 100644 --- a/src/to_typescript/structs.rs +++ b/src/to_typescript/structs.rs @@ -100,6 +100,7 @@ pub fn process_fields<'a>( let has_flatten_attr = utils::get_attribute_arg("serde", "flatten", &field.attrs).is_some(); let serde_skip = utils::get_attribute_arg("serde", "skip", &field.attrs).is_some(); let serde_rename = utils::get_attribute_arg("serde", "rename", &field.attrs); + let type_override = utils::get_attribute_arg("tsync", "ts_type", &field.attrs); if has_flatten_attr || serde_skip { continue; } @@ -123,7 +124,12 @@ pub fn process_fields<'a>( field.ident.map(|i| i.unraw().to_string()).unwrap() }; - let field_type = convert_type(&field.ty); + let mut field_type = convert_type(&field.ty); + + if let Some(type_override) = type_override { + field_type.ts_type = type_override + } + state.types.push_str(&format!( "{space}{field_name}{optional_parameter_token}: {field_type};\n", space = space, diff --git a/test/issue-34/rust.rs b/test/issue-34/rust.rs new file mode 100644 index 0000000..8bd1544 --- /dev/null +++ b/test/issue-34/rust.rs @@ -0,0 +1,7 @@ +#[tsync] +struct SomeStruct { + #[serde(skip)] + foo: ThisIsARandomExternalType, + #[tsync(ts_type = "any")] + foo2: ThisIsARandomExternalType, +} diff --git a/test/issue-34/tsync.sh b/test/issue-34/tsync.sh new file mode 100755 index 0000000..1764bd6 --- /dev/null +++ b/test/issue-34/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-34/typescript.d.ts b/test/issue-34/typescript.d.ts new file mode 100644 index 0000000..fb3e940 --- /dev/null +++ b/test/issue-34/typescript.d.ts @@ -0,0 +1,5 @@ +/* This file is generated and managed by tsync */ + +interface SomeStruct { + foo2: any; +} diff --git a/test/issue-34/typescript.ts b/test/issue-34/typescript.ts new file mode 100644 index 0000000..198a62d --- /dev/null +++ b/test/issue-34/typescript.ts @@ -0,0 +1,5 @@ +/* This file is generated and managed by tsync */ + +export interface SomeStruct { + foo2: any; +} diff --git a/test/test_all.sh b/test/test_all.sh index 89de09f..ad8bd51 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -14,6 +14,7 @@ cd $SCRIPT_DIR ./enum_numeric/tsync.sh ./doc_comments/tsync.sh ./generic/tsync.sh +./issue-34/tsync.sh ./issue-42-serde-rename/tsync.sh ./issue-43/tsync.sh ./issue-55/tsync.sh