diff --git a/ts-rs/tests/issue-70.rs b/ts-rs/tests/issue-70.rs new file mode 100644 index 000000000..a90bd4d92 --- /dev/null +++ b/ts-rs/tests/issue-70.rs @@ -0,0 +1,57 @@ +#![allow(unused)] + +use std::collections::HashMap; +use ts_rs::TS; + +#[test] +fn issue_70() { + type TypeAlias = HashMap; + + #[derive(TS)] + enum Enum { + A(TypeAlias), + B(HashMap), + } + + #[derive(TS)] + struct Struct { + a: TypeAlias, + b: HashMap + } + + assert_eq!(Enum::decl(), "type Enum = { \"A\": Record } | { \"B\": Record };"); + assert_eq!(Struct::decl(), "type Struct = { a: Record, b: Record, };"); +} + +#[test] +fn generic() { + type GenericAlias = HashMap<(A, String), Vec<(B, i32)>>; + + #[derive(TS)] + struct Container { + a: GenericAlias, Vec>, + b: GenericAlias + } + assert_eq!( + Container::decl(), + "type Container = { \ + a: Record<[Array, string], Array<[Array, number]>>, \ + b: Record<[string, string], Array<[string, number]>>, \ + };" + ); + + #[derive(TS)] + struct GenericContainer { + a: GenericAlias, + b: GenericAlias, + c: GenericAlias> + } + assert_eq!( + GenericContainer::<(), ()>::decl(), + "type GenericContainer = { \ + a: Record<[string, string], Array<[string, number]>>, \ + b: Record<[A, string], Array<[B, number]>>, \ + c: Record<[A, string], Array<[Record<[A, string], Array<[B, number]>>, number]>>, \ + };" + ); +} \ No newline at end of file