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:
@ -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;
|
||||
|
Reference in New Issue
Block a user