Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#70761 fix(multiparty): Correct the files t…
Browse files Browse the repository at this point in the history
…ype in parse callback by @hkleungai
  • Loading branch information
hkleungai authored Oct 1, 2024
1 parent a1c6892 commit a163286
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion types/multiparty/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare class Form extends events.EventEmitter {
callback?: (
error: Error | null,
fields: Record<string, string[] | undefined>,
files: Record<string, string[] | undefined>,
files: Record<string, File[] | undefined>,
) => void,
): void;

Expand All @@ -26,6 +26,7 @@ export declare class Form extends events.EventEmitter {
on(event: "error", listener: (err: Error) => void): this;
on(event: "progress", listener: (bytesReceived: number, bytesExpected: number) => void): this;
on(event: "field", listener: (name: string, value: string) => void): this;
on(event: "file", listener: (name: string, value: File) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
}

Expand Down
7 changes: 6 additions & 1 deletion types/multiparty/multiparty-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ http.createServer(function(req: http.IncomingMessage, res: http.ServerResponse)
console.log("Field Name: " + name + ", Field Value: " + value);
});

form.on("file", function(name: string, value: multiparty.File) {
// decide what to do
console.log("File Name: " + name + ", File Path: " + value.path);
});

// Close emitted after form parsed
form.on("close", function() {
console.log("Upload completed!");
Expand All @@ -63,7 +68,7 @@ http.createServer(function(req: http.IncomingMessage, res: http.ServerResponse)
} else {
error; // $ExpectType null
fields; // $ExpectType Record<string, string[] | undefined>
files; // $ExpectType Record<string, string[] | undefined>
files; // $ExpectType Record<string, File[] | undefined>
}
});
}
Expand Down

0 comments on commit a163286

Please sign in to comment.