mirror of
https://github.com/xazukx/ts-rs.git
synced 2026-11-18 22:30:26 +00:00
Enum supports named fields
This commit is contained in:
@@ -93,7 +93,12 @@ fn format_variant(
|
||||
quote!{<#ty as ts_rs::TS>::inline(0)}
|
||||
}
|
||||
},
|
||||
_ => panic!("Don't support variants with these kind of fields")
|
||||
Fields::Named(named) => {
|
||||
let ty = named::named(&name, rename_all, &named)?.inline;
|
||||
|
||||
quote!(#ty)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
|
||||
@@ -2,18 +2,39 @@
|
||||
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(TS)]
|
||||
struct Bar {
|
||||
field: i32
|
||||
}
|
||||
|
||||
#[derive(TS)]
|
||||
struct Foo {
|
||||
bar: Bar
|
||||
}
|
||||
|
||||
#[derive(TS)]
|
||||
enum SimpleEnum {
|
||||
A(String),
|
||||
B(i64),
|
||||
C,
|
||||
D(String, i64)
|
||||
D(String, i64),
|
||||
E(Foo),
|
||||
F {a: i32, b: String}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple_enum() {
|
||||
assert_eq!(Foo::decl(),
|
||||
r#"export interface Foo {
|
||||
bar: Bar,
|
||||
}"#);
|
||||
assert_eq!(
|
||||
SimpleEnum::decl(),
|
||||
r#"export type SimpleEnum = string | number | "C" | [string, number];"#
|
||||
)
|
||||
r#"export type SimpleEnum = string | number | "C" | [string, number] | {
|
||||
bar: Bar,
|
||||
} | {
|
||||
a: number,
|
||||
b: string,
|
||||
};"#
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user