diff --git a/src/lang/ts/mod.rs b/src/lang/ts/mod.rs index a1c8959..792a550 100644 --- a/src/lang/ts/mod.rs +++ b/src/lang/ts/mod.rs @@ -161,7 +161,14 @@ fn datatype_inner(ctx: ExportContext, typ: &DataType) -> Result` to avoid issues with circular references. - DataType::List(def) => format!("{}[]", datatype_inner(ctx, def)?), + DataType::List(def) => { + let dt = datatype_inner(ctx, def)?; + if dt.contains(' ') { + format!("({dt})[]") + } else { + format!("{dt}[]") + } + } DataType::Named(NamedDataType { name, item: NamedDataTypeItem::Tuple(TupleType { fields, .. }), diff --git a/tests/ts.rs b/tests/ts.rs index e262541..49e6c6f 100644 --- a/tests/ts.rs +++ b/tests/ts.rs @@ -153,6 +153,9 @@ fn typescript_types() { // assert_ts!(() => ..5, r#"{ end: 5 }"#); // assert_ts!(() => ..=5, r#"{ end: 5 }"#); + // https://github.com/oscartbeaumont/specta/issues/66 + assert_ts!([Option; 16], r#"(number | null)[]"#); + // assert_ts_export!(DeprecatedType, ""); // assert_ts_export!(DeprecatedTypeWithMsg, ""); // assert_ts_export!(DeprecatedFields, ""); diff --git a/tests/ts_rs/generics.rs b/tests/ts_rs/generics.rs index 081cd81..eb3311d 100644 --- a/tests/ts_rs/generics.rs +++ b/tests/ts_rs/generics.rs @@ -116,7 +116,7 @@ fn generic_struct() { assert_ts_export!( GenericStruct2::<()>, - "export type GenericStruct2 = { a: T; b: [T, T]; c: [T, [T, T]]; d: T[]; e: [T, T][]; f: T[]; g: T[][]; h: [T, T][][] }" + "export type GenericStruct2 = { a: T; b: [T, T]; c: [T, [T, T]]; d: T[]; e: ([T, T])[]; f: T[]; g: T[][]; h: (([T, T])[])[] }" ) }