From 5606434bdf5184e470162d908b19b1d53f332855 Mon Sep 17 00:00:00 2001 From: anzharip <10259593+anzharip@users.noreply.github.com> Date: Tue, 2 Nov 2021 06:04:21 +0700 Subject: [PATCH] fix: typing update from busboy --- src/index.ts | 11 ++++++++--- test/index.spec.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index c2ca860..09fc81e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { ParsedMultipartFormData } from "./types/parsed-multipart-form-data.type import { Config } from "./types/config.type"; export default async function parseMultipartFormData( - request: HttpRequest & { headers: { "content-type": string } }, + request: HttpRequest, options?: Config ): Promise { return new Promise((resolve, reject) => { @@ -16,9 +16,14 @@ export default async function parseMultipartFormData( let busboy; if (options) { - busboy = new Busboy({ headers: request.headers, ...options }); + busboy = new Busboy({ + headers: (request.headers as unknown) as Busboy.BusboyHeaders, + ...options, + }); } else { - busboy = new Busboy({ headers: request.headers }); + busboy = new Busboy({ + headers: (request.headers as unknown) as Busboy.BusboyHeaders, + }); } busboy.on( diff --git a/test/index.spec.ts b/test/index.spec.ts index f12ac78..ee11f0b 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -4,7 +4,7 @@ import fs from "fs"; import parseMultipartFormData from "../src/index"; describe("index.js", () => { - let request: HttpRequest & { headers: { "content-type": string } }; + let request: HttpRequest; beforeEach(async () => { const file1 = fs.readFileSync("test/fixture/dummy-data.json"); @@ -50,6 +50,13 @@ describe("index.js", () => { }).rejects.toThrow(); }); + it("should reject the promise due to missing content-type", async () => { + delete request.headers["content-type"]; + expect(async () => { + await parseMultipartFormData(request); + }).rejects.toThrow(); + }); + it("should accept options parameter, parse only one field", async () => { const { fields } = await parseMultipartFormData(request, { limits: { fields: 1 },