Skip to content

Commit

Permalink
fix: allow nested objects in JsonArray type (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Jan 10, 2025
1 parent c600997 commit f08b20e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/good-tables-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"uploadthing": patch
"@uploadthing/shared": patch
---

fix: allow deeply nested objects when using JsonArray
2 changes: 1 addition & 1 deletion packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { MimeType } from "@uploadthing/mime-types";
import type { AllowedFileType } from "./file-types";

export type JsonValue = string | number | boolean | null | undefined;
export type JsonArray = JsonValue[];
export type JsonObject = { [key: string]: JsonValue | JsonObject | JsonArray };
export type JsonArray = (JsonValue | JsonObject)[];
export type Json = JsonValue | JsonObject | JsonArray;

export type Overwrite<T, U> = Omit<T, keyof U> & U;
Expand Down
11 changes: 11 additions & 0 deletions packages/uploadthing/test/upload-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ it("smoke", async () => {
});
expect(metadata).toEqual({ header1: "woohoo", userId: "123" });
});

it("allows nested structure in output", () => {
const f = createBuilder<{ req: Request; res: undefined; event: undefined }>();

f(["image"]).onUploadComplete(() => {
return {
foo: "br",
arr: [{ bar: "baz" }],
};
});
});

0 comments on commit f08b20e

Please sign in to comment.