mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 11:02:11 +08:00
Merge pull request #26383 from dannycochran/patch-10
plugin function expects SuperAgentRequest
This commit is contained in:
2
types/superagent/index.d.ts
vendored
2
types/superagent/index.d.ts
vendored
@@ -150,7 +150,7 @@ declare namespace request {
|
||||
write(data: string | Buffer, encoding?: string): this;
|
||||
}
|
||||
|
||||
type Plugin = (req: Request) => void;
|
||||
type Plugin = (req: SuperAgentRequest) => void;
|
||||
|
||||
interface ProgressEvent {
|
||||
direction: 'download' | 'upload';
|
||||
|
||||
@@ -390,3 +390,18 @@ request
|
||||
.then(response => {
|
||||
// reads 404 page as a successful response
|
||||
});
|
||||
|
||||
// Test that the "Plugin" type from "use" provides a SuperAgentRequest rather than a Request,
|
||||
// which has additional properties.
|
||||
const echoPlugin = (request: request.SuperAgentRequest) => {
|
||||
req.url = '' + req.url;
|
||||
req.cookies = '' + req.cookies;
|
||||
if (req.method) {
|
||||
req.url = '/echo';
|
||||
}
|
||||
};
|
||||
|
||||
request
|
||||
.get('/echo')
|
||||
.use(echoPlugin)
|
||||
.end();
|
||||
|
||||
Reference in New Issue
Block a user