#![allow(unused)] use std::collections::HashMap; use ts_rs::TS; type TypeAlias = HashMap; #[derive(TS)] #[ts(export, export_to = "issue_70/")] enum Enum { A(TypeAlias), B(HashMap), } #[derive(TS)] #[ts(export, export_to = "issue_70/")] struct Struct { a: TypeAlias, b: HashMap, } #[test] fn issue_70() { assert_eq!( Enum::decl(), "type Enum = { \"A\": { [key in string]?: string } } | { \"B\": { [key in string]?: string } };" ); assert_eq!( Struct::decl(), "type Struct = { a: { [key in string]?: string }, b: { [key in string]?: string }, };" ); } #[derive(TS)] #[ts(export, export_to = "issue_70/")] struct GenericType { foo: T, bar: U, } type GenericAlias = GenericType<(A, String), Vec<(B, i32)>>; #[derive(TS)] #[ts(export, export_to = "issue_70/")] struct Container { a: GenericAlias, Vec>, b: GenericAlias, } #[derive(TS)] #[ts(export, export_to = "issue_70/")] struct GenericContainer { a: GenericAlias, b: GenericAlias, c: GenericAlias>, } #[test] fn generic() { assert_eq!( Container::decl(), "type Container = { \ a: GenericType<[Array, string], Array<[Array, number]>>, \ b: GenericType<[string, string], Array<[string, number]>>, \ };" ); assert_eq!( GenericContainer::<(), ()>::decl(), "type GenericContainer = { \ a: GenericType<[string, string], Array<[string, number]>>, \ b: GenericType<[A, string], Array<[B, number]>>, \ c: GenericType<[A, string], Array<[GenericType<[A, string], Array<[B, number]>>, number]>>, \ };" ); }