#![allow(dead_code)] use std::collections::{BTreeMap, HashMap, HashSet}; use ts_rs::TS; #[derive(TS)] #[ts(export, export_to = "hashmap/")] struct Hashes { map: HashMap, set: HashSet, } #[test] fn hashmap() { assert_eq!( Hashes::decl(), "type Hashes = { map: { [key: string]: string }, set: Array, };" ) } struct CustomHasher {} type CustomHashMap = HashMap; type CustomHashSet = HashSet; #[derive(TS)] #[ts(export, export_to = "hashmap/")] struct HashesHasher { map: CustomHashMap, set: CustomHashSet, } #[test] fn hashmap_with_custom_hasher() { assert_eq!( HashesHasher::decl(), "type HashesHasher = { map: { [key: string]: string }, set: Array, };" ) } #[derive(TS, Eq, PartialEq, Hash)] #[ts(export, export_to = "hashmap/")] struct CustomKey(String); #[derive(TS)] #[ts(export, export_to = "hashmap/")] struct CustomValue; #[derive(TS)] #[ts(export, export_to = "hashmap/")] struct HashMapWithCustomTypes { map: HashMap, } #[derive(TS)] #[ts(export, export_to = "hashmap/")] struct BTreeMapWithCustomTypes { map: BTreeMap, } #[test] fn with_custom_types() { assert_eq!( HashMapWithCustomTypes::inline(), BTreeMapWithCustomTypes::inline() ); assert_eq!( HashMapWithCustomTypes::decl(), "type HashMapWithCustomTypes = { map: { [key: CustomKey]: CustomValue }, };" ); }