diff --git a/types/superagent/index.d.ts b/types/superagent/index.d.ts index 971cc3c4c2..7c1898cdc2 100644 --- a/types/superagent/index.d.ts +++ b/types/superagent/index.d.ts @@ -6,6 +6,7 @@ // Shrey Jain // Alec Zopf // Adam Haglund +// Lukas Elmer // 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; + agent(): this & Request; serialize: { [type: string]: Serializer }; parse: { [type: string]: Parser }; } diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index c063c819be..44ef7cf773 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -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();