Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
6abf8fdfc2 fix(types): correct FormData iterator return types to include File
`FormData.values()` and `FormData.entries()` incorrectly typed their
return values as `string` instead of `FormDataEntryValue` (string | File),
inconsistent with `get()`, `getAll()`, and `forEach()` in the same interface.

Closes #27194

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-19 15:17:26 +00:00
2 changed files with 28 additions and 2 deletions

View File

@@ -1680,8 +1680,8 @@ interface FormData {
set(name: string, blobValue: Blob, filename?: string): void;
forEach(callbackfn: (value: Bun.FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[string, string]>;
values(): IterableIterator<Bun.FormDataEntryValue>;
entries(): IterableIterator<[string, Bun.FormDataEntryValue]>;
}
declare var FormData: Bun.__internal.UseLibDomIfAvailable<"FormData", { prototype: FormData; new (): FormData }>;

View File

@@ -0,0 +1,26 @@
import { expect, test } from "bun:test";
test("FormData.values() returns File objects, not just strings", () => {
const fd = new FormData();
const file = new File(["content"], "test.txt", { type: "text/plain" });
fd.append("textField", "hello");
fd.append("fileField", file);
const values = [...fd.values()];
expect(values).toHaveLength(2);
expect(values[0]).toBe("hello");
expect(values[1]).toBeInstanceOf(File);
});
test("FormData.entries() returns File objects in value position", () => {
const fd = new FormData();
const file = new File(["content"], "test.txt", { type: "text/plain" });
fd.append("textField", "hello");
fd.append("fileField", file);
const entries = [...fd.entries()];
expect(entries).toHaveLength(2);
expect(entries[0]).toEqual(["textField", "hello"]);
expect(entries[1][0]).toBe("fileField");
expect(entries[1][1]).toBeInstanceOf(File);
});