Merge pull request #30920 from lukaselmer/feature/improve-superagent-agent

improve superagent.agent() typing
This commit is contained in:
Andrew Casey
2018-12-04 10:29:26 -08:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
// Shrey Jain <https://github.com/shreyjain1994>
// Alec Zopf <https://github.com/zopf>
// Adam Haglund <https://github.com/beeequeue>
// Lukas Elmer <https://github.com/lukaselmer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -45,7 +46,7 @@ declare namespace request {
// tslint:disable-next-line:unified-signatures
(method: string, url: string): SuperAgentRequest;
agent(): SuperAgent<SuperAgentRequest>;
agent(): this & Request;
serialize: { [type: string]: Serializer };
parse: { [type: string]: Parser };
}

View File

@@ -421,3 +421,16 @@ request
.get('/echo')
.use(echoPlugin)
.end();
async function testDefaultOptions() {
// Default options for multiple requests
const agentWithDefaultOptions = request
.agent()
.use(() => null)
.auth('digest', 'secret', { type: 'auto' });
await agentWithDefaultOptions.get('/with-plugin-and-auth');
await agentWithDefaultOptions.get('/also-with-plugin-and-auth');
}
testDefaultOptions();