diff --git a/src/generator/dts.ts b/src/generator/dts.ts index a397247..ecda1dd 100644 --- a/src/generator/dts.ts +++ b/src/generator/dts.ts @@ -179,7 +179,15 @@ function getTsType( return "any"; } if (Array.isArray(type.type)) { - return type.type.map((t) => TYPE_MAP[t]).join("|"); + return type.type + .map((t) => { + // object is typed to an empty string by default, we need to type as object + if (t === "object" && type.type.length > 1) { + return `{\n` + _genTypes(type, " ", opts).join("\n") + `\n}`; + } + return TYPE_MAP[t]; + }) + .join("|"); } if (type.type === "array") { return `Array<${getTsType(type.items, opts)}>`; diff --git a/test/types.test.ts b/test/types.test.ts index 461da68..57c4ed2 100644 --- a/test/types.test.ts +++ b/test/types.test.ts @@ -205,4 +205,22 @@ export interface Untyped { }" `); }); + + it("array - literal and object entries", async () => { + const schema = generateTypes( + await resolveSchema({ + foo: { bar: ["first", "second", { third: true }] }, + }) + ); + expect(schema).toMatchInlineSnapshot(` + "export interface Untyped { + foo: { + /** @default [\\"first\\",\\"second\\",{\\"third\\":true}] */ + bar: Array, + }, + }" + `); + }); });