diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index afe3ddb21..68509e25c 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -440,11 +440,11 @@ impl TS for Option { "called Option::name_with_type_args with {} args", args.len() ); - format!("{} | null", args[0]) + format!("({} | null)", args[0]) } fn inline() -> String { - format!("{} | null", T::inline()) + format!("({} | null)", T::inline()) } fn dependencies() -> Vec @@ -471,11 +471,11 @@ impl TS for Result { "called Result::name_with_type_args with {} args", args.len() ); - format!("{{ ok: {} }} | {{ err: {} }}", args[0], args[1]) + format!("({{ ok: {} }} | {{ err: {} }})", args[0], args[1]) } fn inline() -> String { - format!("{{ ok: {} }} | {{ err: {} }}", T::inline(), E::inline()) + format!("({{ ok: {} }} | {{ err: {} }})", T::inline(), E::inline()) } fn dependencies() -> Vec diff --git a/ts-rs/tests/optional_field.rs b/ts-rs/tests/optional_field.rs index 807e9daf1..3f53278fe 100644 --- a/ts-rs/tests/optional_field.rs +++ b/ts-rs/tests/optional_field.rs @@ -14,7 +14,7 @@ struct Optional { #[test] fn test() { #[cfg(not(feature = "serde-compat"))] - assert_eq!(Optional::inline(), "{ a?: number, b: string | null, }"); + assert_eq!(Optional::inline(), "({ a?: number, b: string | null, })"); #[cfg(feature = "serde-compat")] - assert_eq!(Optional::inline(), "{ a?: number, b?: string, }") + assert_eq!(Optional::inline(), "({ a?: number, b?: string, })") } diff --git a/ts-rs/tests/result.rs b/ts-rs/tests/result.rs index 65e7ad33f..cd14b7f4f 100644 --- a/ts-rs/tests/result.rs +++ b/ts-rs/tests/result.rs @@ -11,6 +11,6 @@ struct Fallible { fn test() { assert_eq!( Fallible::inline(), - "{ a: { ok: number } | { err: string }, }" + "({ a: { ok: number } | { err: string }, })" ) }