mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Merge pull request #32540 from BendingBender/responselike
[responselike] Add types
This commit is contained in:
Vendored
+34
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user