fix(http): move destructuring inside {Request,Response}Options ctor

Previously the RequestOptions/ResponseOptions classes had constructors
with a destructured argument hash (represented by the
{Request,Response}OptionsArgs type). This type consists entirely of
optional members.

This produces a .d.ts file which includes the constructor declaration:

constructor({param, otherParam}?: OptionsArgs);

However, this declaration doesn't type-check properly. TypeScript
determines the actual type of the hash parameter to be OptionsArgs | undefined,
which it then concludes does not have a `param` or `otherParam` member.

This is a bug in TypeScript ( https://github.com/microsoft/typescript/issues/10078 ).
As a workaround, destructuring is moved inside the method, where it does not produce
broken artifacts in the .d.ts.

Fixes #16663.
This commit is contained in:
Alex Rickabaugh
2017-06-06 15:58:38 -07:00
parent 65d49d5c94
commit c2d31fb01e
3 changed files with 6 additions and 6 deletions

View File

@ -79,9 +79,8 @@ export class RequestOptions {
responseType: ResponseContentType|null;
// TODO(Dzmitry): remove search when this.search is removed
constructor(
{method, headers, body, url, search, params, withCredentials,
responseType}: RequestOptionsArgs = {}) {
constructor(opts: RequestOptionsArgs = {}) {
const {method, headers, body, url, search, params, withCredentials, responseType} = opts;
this.method = method != null ? normalizeMethodName(method) : null;
this.headers = headers != null ? headers : null;
this.body = body != null ? body : null;