Merge pull request #32540 from BendingBender/responselike

[responselike] Add types
This commit is contained in:
Pranav Senthilnathan
2019-01-29 17:03:33 -08:00
committed by GitHub
4 changed files with 68 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
// Type definitions for responselike 1.0
// Project: https://github.com/lukechilds/responselike#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { IncomingMessage } from 'http';
import { Stream } from 'stream';
export = ResponseLike;
/**
* Returns a streamable response object similar to a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
*/
declare class ResponseLike extends Stream.Readable {
statusCode: number;
headers: { [header: string]: string | string[] | undefined };
body: Buffer;
url: string;
/**
* @param statusCode HTTP response status code.
* @param headers HTTP headers object. Keys will be automatically lowercased.
* @param body A Buffer containing the response body. The Buffer contents will be streamable but is also exposed directly as `response.body`.
* @param url Request URL string.
*/
constructor(
statusCode: number,
headers: { [header: string]: string | string[] | undefined },
body: Buffer,
url: string
);
}
+10
View File
@@ -0,0 +1,10 @@
import Response = require('responselike');
const response = new Response(200, { foo: 'bar' }, Buffer.from('Hi!'), 'https://example.com');
response.statusCode; // $ExpectType number
response.headers; // $ExpectType { [header: string]: string | string[] | undefined; }
response.body; // $ExpectType Buffer
response.url; // $ExpectType string
response.pipe(process.stdout);
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"responselike-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }