Repository: octokit/webhooks.js
Pull request #403 (2021-01-15 20:48:45)

refactor: define `body` property on `IncomingMessage`
This arguments the type of `IncomingMessage` so that `body` is defined, meaning we don't have to use `@ts-expect-error`.

G-Rath: ```
Error: node_modules/@types/express-serve-static-core/index.d.ts(219,18): error TS2430: Interface 'Request<P, ResBody, ReqBody, ReqQuery>' incorrectly extends interface 'IncomingMessage'.
  Types of property 'body' are incompatible.
    Type 'ReqBody' is not assignable to type 'EventTypesPayload'.
```

Well thats sad but not entirely unexpected - I'll look into this later to see if I can make TS happy, but probably not worth it tbh
G-Rath: Except it turns out we don't  need `@types/express` 🎉 

Patch:
diff --git a/package-lock.json b/package-lock.json
index 629553a..1ebe414 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2604,31 +2604,12 @@
         "@babel/types": "^7.3.0"
       }
     },
-    "@types/body-parser": {
-      "version": "1.19.0",
-      "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz",
-      "integrity": "sha512-W98JrE0j2K78swW4ukqMleo8R7h/pFETjM2DQ90MF6XK2i4LO4W3gQ71Lt4w3bfm2EvVSyWHplECvB5sK22yFQ==",
-      "dev": true,
-      "requires": {
-        "@types/connect": "*",
-        "@types/node": "*"
-      }
-    },
     "@types/color-name": {
       "version": "1.1.1",
       "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
       "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
       "dev": true
     },
-    "@types/connect": {
-      "version": "3.4.33",
-      "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
-      "integrity": "sha512-2+FrkXY4zllzTNfJth7jOqEHC+enpLeGslEhpnTAkg21GkRrWV4SsAtqchtT4YS9/nODBU2/ZfsBY2X4J/dX7A==",
-      "dev": true,
-      "requires": {
-        "@types/node": "*"
-      }
-    },
     "@types/debug": {
       "version": "4.1.5",
       "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
@@ -2641,29 +2622,6 @@
       "integrity": "sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==",
       "dev": true
     },
-    "@types/express": {
-      "version": "4.17.9",
-      "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.9.tgz",
-      "integrity": "sha512-SDzEIZInC4sivGIFY4Sz1GG6J9UObPwCInYJjko2jzOf/Imx/dlpume6Xxwj1ORL82tBbmN4cPDIDkLbWHk9hw==",
-      "dev": true,
-      "requires": {
-        "@types/body-parser": "*",
-        "@types/express-serve-static-core": "*",
-        "@types/qs": "*",
-        "@types/serve-static": "*"
-      }
-    },
-    "@types/express-serve-static-core": {
-      "version": "4.17.13",
-      "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.13.tgz",
-      "integrity": "sha512-RgDi5a4nuzam073lRGKTUIaL3eF2+H7LJvJ8eUnCI0wA6SNjXc44DCmWNiTLs/AZ7QlsFWZiw/gTG3nSQGL0fA==",
-      "dev": true,
-      "requires": {
-        "@types/node": "*",
-        "@types/qs": "*",
-        "@types/range-parser": "*"
-      }
-    },
     "@types/glob": {
       "version": "7.1.3",
       "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz",
@@ -2717,12 +2675,6 @@
         "pretty-format": "^26.0.0"
       }
     },
-    "@types/mime": {
-      "version": "2.0.3",
-      "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.3.tgz",
-      "integrity": "sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q==",
-      "dev": true
-    },
     "@types/minimatch": {
       "version": "3.0.3",
       "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
@@ -2758,34 +2710,12 @@
       "integrity": "sha512-UEyp8LwZ4Dg30kVU2Q3amHHyTn1jEdhCIE59ANed76GaT1Vp76DD3ZWSAxgCrw6wJ0TqeoBpqmfUHiUDPs//HQ==",
       "dev": true
     },
-    "@types/qs": {
-      "version": "6.9.5",
-      "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.5.tgz",
-      "integrity": "sha512-/JHkVHtx/REVG0VVToGRGH2+23hsYLHdyG+GrvoUGlGAd0ErauXDyvHtRI/7H7mzLm+tBCKA7pfcpkQ1lf58iQ==",
-      "dev": true
-    },
-    "@types/range-parser": {
-      "version": "1.2.3",
-      "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz",
-      "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==",
-      "dev": true
-    },
     "@types/retry": {
       "version": "0.12.0",
       "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
       "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==",
       "dev": true
     },
-    "@types/serve-static": {
-      "version": "1.13.7",
-      "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.7.tgz",
-      "integrity": "sha512-3diZWucbR+xTmbDlU+FRRxBf+31OhFew7cJXML/zh9NmvSPTNoFecAwHB66BUqFgENJtqMiyl7JAwUE/siqdLw==",
-      "dev": true,
-      "requires": {
-        "@types/mime": "*",
-        "@types/node": "*"
-      }
-    },
     "@types/stack-utils": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz",
diff --git a/package.json b/package.json
index 5ef91d4..46f456b 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,6 @@
     "@pika/plugin-build-node": "^0.9.2",
     "@pika/plugin-ts-standard-pkg": "^0.9.2",
     "@types/debug": "^4.1.5",
-    "@types/express": "^4.17.6",
     "@types/jest": "^26.0.9",
     "@types/node": "^14.0.14",
     "@types/prettier": "^2.0.0",
diff --git a/src/middleware/get-payload.ts b/src/middleware/get-payload.ts
index 7595cc1..bfb8b88 100644
--- a/src/middleware/get-payload.ts
+++ b/src/middleware/get-payload.ts
@@ -4,13 +4,18 @@ import AggregateError from "aggregate-error";
 import { IncomingMessage } from "http";
 import { EventTypesPayload } from "../generated/get-webhook-payload-type-from-event";
 
+declare module "http" {
+  interface IncomingMessage {
+    body?: EventTypesPayload;
+  }
+}
+
 export function getPayload(
   request: IncomingMessage
 ): Promise<EventTypesPayload> {
   // If request.body already exists we can stop here
   // See https://github.com/octokit/webhooks.js/pull/23
 
-  // @ts-expect-error
   if (request.body) return Promise.resolve(request.body);
 
   return new Promise((resolve, reject) => {


Test patch:
diff --git a/test/integration/server-test.ts b/test/integration/server-test.ts
index 06a241d..0a9ca1e 100644
--- a/test/integration/server-test.ts
+++ b/test/integration/server-test.ts
@@ -182,7 +182,6 @@ describe("server-test", () => {
     const server = http.createServer((req, res) => {
       req.once("data", (chunk) => dataChunks.push(chunk));
       req.once("end", () => {
-        // @ts-expect-error
         req.body = JSON.parse(Buffer.concat(dataChunks).toString());
         api.middleware(req, res);