Skip to content

Commit

Permalink
Use inline instead of name, Vec<string> was turning into Array
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo committed Jan 29, 2024
1 parent 1dc210b commit ef56d7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion macros/src/types/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn format_type(ty: &Type, dependencies: &mut Dependencies, generics: &Generi
}

return quote!(
match <#generic_ident>::name().as_str() {
match <#generic_ident>::inline().as_str() {
// When exporting a generic, the default type used is `()`,
// which gives "null" when calling `.name()`. In this case, we
// want to preserve the type param's identifier as the name used
Expand Down
5 changes: 3 additions & 2 deletions ts-rs/tests/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fn generic_struct() {
}

#[test]
// https://github.com/Aleph-Alpha/ts-rs/issues/56 TODO
fn inline() {
#[derive(TS)]
struct Generic<T> {
Expand All @@ -159,13 +160,13 @@ fn inline() {
#[ts(inline)]
gi: Generic<String>,
#[ts(flatten)]
t: Generic<String>,
t: Generic<Vec<String>>,
}

assert_eq!(Generic::<()>::decl(), "type Generic<T> = { t: T, }");
assert_eq!(
Container::decl(),
"type Container = { g: Generic<string>, gi: { t: string, }, t: string, }"
"type Container = { g: Generic<string>, gi: { t: string, }, t: Array<string>, }"
);
}

Expand Down

0 comments on commit ef56d7a

Please sign in to comment.