#![cfg(feature = "serde_json")] #![allow(unused)] use ts_rs::TS; #[derive(TS)] #[ts(export, export_to = "serde_json_impl/")] struct UsingSerdeJson { num: serde_json::Number, map1: serde_json::Map, map2: serde_json::Map, map3: serde_json::Map>, map4: serde_json::Map, map5: serde_json::Map, any: serde_json::Value, } #[test] fn using_serde_json() { assert_eq!(serde_json::Number::inline(), "number"); assert_eq!( serde_json::Map::::inline(), "{ [key: string]: number }" ); assert_eq!( serde_json::Value::decl(), "type JsonValue = number | string | Array | { [key: string]: JsonValue };", ); assert_eq!( UsingSerdeJson::decl(), "type UsingSerdeJson = { \ num: number, \ map1: { [key: string]: number }, \ map2: { [key: string]: UsingSerdeJson }, \ map3: { [key: string]: { [key: string]: number } }, \ map4: { [key: string]: number }, \ map5: { [key: string]: JsonValue }, \ any: JsonValue, \ };" ) } #[derive(TS)] #[ts(export, export_to = "serde_json_impl/")] struct InlinedValue { #[ts(inline)] any: serde_json::Value, } #[test] fn inlined_value() { assert_eq!( InlinedValue::decl(), "type InlinedValue = { \ any: number | string | Array | { [key: string]: JsonValue }, \ };" ); } #[derive(TS)] #[ts(export, export_to = "serde_json_impl/")] struct Simple { json: serde_json::Value, }