mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
raw-body: conditional return type based on options
This commit is contained in:
Vendored
+12
-9
@@ -4,13 +4,16 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
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<string | Buffer>;
|
||||
declare function getRawBody(stream: Readable, options: (getRawBody.Options & { encoding: getRawBody.Encoding }) | getRawBody.Encoding): Promise<string>;
|
||||
declare function getRawBody(stream: Readable, options?: getRawBody.Options): Promise<Buffer>;
|
||||
|
||||
export = getRawBody;
|
||||
|
||||
@@ -2,11 +2,11 @@ import getRawBody = require("raw-body");
|
||||
|
||||
const stream: any = {};
|
||||
|
||||
const simple = getRawBody(stream);
|
||||
const simple: Promise<Buffer> = getRawBody(stream);
|
||||
|
||||
const withEncoding = getRawBody(stream, "utf-8");
|
||||
const withEncoding: Promise<string> = getRawBody(stream, "utf-8");
|
||||
|
||||
const withOptions = getRawBody(stream, {
|
||||
const withOptions: Promise<string> = getRawBody(stream, {
|
||||
encoding: "utf-8",
|
||||
length: 1024,
|
||||
limit: 512
|
||||
|
||||
Reference in New Issue
Block a user