diff --git a/raw-body/index.d.ts b/raw-body/index.d.ts
index a99f2c51c2..94131c5764 100644
--- a/raw-body/index.d.ts
+++ b/raw-body/index.d.ts
@@ -4,13 +4,16 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///
+
import { Readable } from "stream";
declare namespace getRawBody {
+ export type Encoding = string | true;
+
export interface Options {
length?: number;
limit?: number;
- encoding?: string;
+ encoding?: Encoding;
}
export interface RawBodyError extends Error {
@@ -19,18 +22,18 @@ declare namespace getRawBody {
expected?: number;
received?: number;
encoding?: string;
- status?: number;
- statusCode?: number;
- type?: string;
+ status: number;
+ statusCode: number;
+ type: string;
}
-
- export type Callback = (err: RawBodyError, res: string | Buffer) => void;
}
-declare function getRawBody(stream: Readable, callback: getRawBody.Callback): void;
-declare function getRawBody(stream: Readable, options: getRawBody.Options | string, callback: getRawBody.Callback): void;
+declare function getRawBody(stream: Readable, callback: (err: getRawBody.RawBodyError, body: Buffer) => void): void;
+declare function getRawBody(stream: Readable, options: (getRawBody.Options & { encoding: getRawBody.Encoding }) | getRawBody.Encoding, callback: (err: getRawBody.RawBodyError, body: string) => void): void;
+declare function getRawBody(stream: Readable, options: getRawBody.Options, callback: (err: getRawBody.RawBodyError, body: Buffer) => void): void;
-declare function getRawBody(stream: Readable, options?: getRawBody.Options | string): Promise;
+declare function getRawBody(stream: Readable, options: (getRawBody.Options & { encoding: getRawBody.Encoding }) | getRawBody.Encoding): Promise;
+declare function getRawBody(stream: Readable, options?: getRawBody.Options): Promise;
export = getRawBody;
diff --git a/raw-body/raw-body-tests.ts b/raw-body/raw-body-tests.ts
index f23160c876..ad6065537d 100644
--- a/raw-body/raw-body-tests.ts
+++ b/raw-body/raw-body-tests.ts
@@ -2,11 +2,11 @@ import getRawBody = require("raw-body");
const stream: any = {};
-const simple = getRawBody(stream);
+const simple: Promise = getRawBody(stream);
-const withEncoding = getRawBody(stream, "utf-8");
+const withEncoding: Promise = getRawBody(stream, "utf-8");
-const withOptions = getRawBody(stream, {
+const withOptions: Promise = getRawBody(stream, {
encoding: "utf-8",
length: 1024,
limit: 512