feat(hijackresponse): new type definition (#47540)

This commit is contained in:
Matthias Kunnen 2020-09-15 00:14:53 +02:00 committed by GitHub
parent 84fd109a44
commit 4851ad40fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import * as express from 'express';
import * as hijackResponse from 'hijackresponse';
const app = express();
app.use((req, res, next) => {
hijackResponse(res, (err, res) => {
res.setHeader("X-Hijacked", "yes!");
res.removeHeader("Content-Length");
res.pipe(res);
});
next();
});

23
types/hijackresponse/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
// Type definitions for hijackresponse 4.0
// Project: https://github.com/gustavnikolaj/hijackresponse
// Definitions by: Matthias Kunnen <https://github.com/MatthiasKunnen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.5
import express = require('express');
import { Readable } from 'stream';
declare namespace e {
interface HijackedResponse<ResBody = any>
extends express.Response<ResBody>,
Omit<Readable, keyof express.Response> {
destroyHijacked: () => boolean;
unhijack: () => express.Response;
}
}
declare function e<ResBody = any>(
res: express.Response<ResBody>,
callback: (err: null, res: e.HijackedResponse<ResBody>) => void,
): void;
export = e;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"hijackresponse-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }