Skip to content

Commit

Permalink
Merge pull request #199 from escritorio-gustavo/improve-references
Browse files Browse the repository at this point in the history
Improve support for references
  • Loading branch information
NyxCode authored Jan 22, 2024
2 parents 35066f3 + 8d23fcd commit 3ecad90
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions macros/src/types/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub fn format_type(ty: &Type, dependencies: &mut Dependencies, generics: &Generi
dependencies.append(tuple_struct.dependencies);
return tuple_struct.inline;
}
Type::Reference(syn::TypeReference { ref elem, .. }) => {
return format_type(elem, dependencies, generics)
}
_ => (),
};

Expand Down
15 changes: 15 additions & 0 deletions ts-rs/tests/references.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use ts_rs::TS;

#[test]
fn references() {
#[derive(TS)]
#[allow(dead_code)]
struct FullOfRefs<'a> {
str_slice: &'a str,
ref_slice: &'a [&'a str],
num_ref: &'a i32,
}

assert_eq!(FullOfRefs::inline(), "{ str_slice: string, ref_slice: Array<string>, num_ref: number, }")
}

11 changes: 11 additions & 0 deletions ts-rs/tests/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ fn interface() {
assert_eq!(Interface::inline(), "{ a: Array<number>, }")
}

#[test]
fn slice_ref() {
#[derive(TS)]
struct Interface<'a> {
#[allow(dead_code)]
a: &'a [&'a str]
}

assert_eq!(Interface::inline(), "{ a: Array<string>, }")
}

#[test]
fn newtype() {
#[derive(TS)]
Expand Down

0 comments on commit 3ecad90

Please sign in to comment.