[@types/got] Fix for extended got instance when options are used (#34804)

* Fix extended got instance requiring duplicate `json: true`

* Use partials rather than base options
This commit is contained in:
Matthew Bull
2019-04-17 22:41:18 +01:00
committed by Armando Aguirre
parent 621b0e6094
commit 548df2e56f
2 changed files with 12 additions and 2 deletions

View File

@@ -269,6 +269,8 @@ got.extend({ method: 'POST' }).extend({ headers: {} }).stream('/example');
// $ExpectType Promise<any>
got.extend({ json: true })('/example').then(({ body }) => body);
// $ExpectType Promise<any>
got.extend({ json: true })('/example', { query: {} }).then(({ body }) => body);
// $ExpectType Promise<any>
got.extend({ baseUrl: 'https://localhost' }).extend({ json: true })('/example').then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({})('/example').then(({ body }) => body);
@@ -276,20 +278,28 @@ got.extend({})('/example').then(({ body }) => body);
// $ExpectType Promise<Buffer>
got.extend({ form: true, encoding: null })('/example').then(({ body }) => body);
// $ExpectType Promise<Buffer>
got.extend({ form: true, encoding: null })('/example', { query: {} }).then(({ body }) => body);
// $ExpectType Promise<Buffer>
got.extend({ form: true, encoding: null, body: {} })('/example').then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ form: true, encoding: 'utf8' })('/example').then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ form: true, encoding: 'utf8' })('/example', { query: {} }).then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ form: true, encoding: 'utf8', body: {} })('/example').then(({ body }) => body);
// Body options:
// $ExpectType Promise<Buffer>
got.extend({ encoding: null })('/example').then(({ body }) => body);
// $ExpectType Promise<Buffer>
got.extend({ encoding: null, body: '{}' })('/example').then(({ body }) => body);
// $ExpectType Promise<Buffer>
got.extend({ encoding: null, body: '{}' })('/example', { query: {} }).then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ encoding: 'utf8' })('/example').then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ encoding: 'utf8', body: '{}' })('/example').then(({ body }) => body);
// $ExpectType Promise<string>
got.extend({ encoding: 'utf8', body: '{}' })('/example', { query: {} }).then(({ body }) => body);
// Test retry options.
got('http://todomvc.com', { retry: 2 });

View File

@@ -90,12 +90,12 @@ declare namespace got {
interface GotJSONFn {
(url: GotUrl): GotPromise<any>;
(url: GotUrl, options: GotJSONOptions): GotPromise<any>;
(url: GotUrl, options: Partial<GotJSONOptions>): GotPromise<any>;
}
interface GotFormFn<T extends string | null> {
(url: GotUrl): GotPromise<T extends null ? Buffer : string>;
(url: GotUrl, options: GotFormOptions<T>): GotPromise<T extends null ? Buffer : string>;
(url: GotUrl, options: Partial<GotFormOptions<T>>): GotPromise<T extends null ? Buffer : string>;
}
interface GotBodyFn<T extends string | null> {