#![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 in string]?: number }" ); assert_eq!( serde_json::Value::decl(), "type JsonValue = number | string | Array | { [key in string]?: JsonValue };", ); assert_eq!( UsingSerdeJson::decl(), "type UsingSerdeJson = { \ num: number, \ map1: { [key in string]?: number }, \ map2: { [key in string]?: UsingSerdeJson }, \ map3: { [key in string]?: { [key in string]?: number } }, \ map4: { [key in string]?: number }, \ map5: { [key in 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 in string]?: JsonValue }, \ };" ); } #[derive(TS)] #[ts(export, export_to = "serde_json_impl/")] struct Simple { json: serde_json::Value, }