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:
parent
65d49d5c94
commit
c2d31fb01e
@ -79,9 +79,8 @@ export class RequestOptions {
|
|||||||
responseType: ResponseContentType|null;
|
responseType: ResponseContentType|null;
|
||||||
|
|
||||||
// TODO(Dzmitry): remove search when this.search is removed
|
// TODO(Dzmitry): remove search when this.search is removed
|
||||||
constructor(
|
constructor(opts: RequestOptionsArgs = {}) {
|
||||||
{method, headers, body, url, search, params, withCredentials,
|
const {method, headers, body, url, search, params, withCredentials, responseType} = opts;
|
||||||
responseType}: RequestOptionsArgs = {}) {
|
|
||||||
this.method = method != null ? normalizeMethodName(method) : null;
|
this.method = method != null ? normalizeMethodName(method) : null;
|
||||||
this.headers = headers != null ? headers : null;
|
this.headers = headers != null ? headers : null;
|
||||||
this.body = body != null ? body : null;
|
this.body = body != null ? body : null;
|
||||||
|
@ -65,7 +65,8 @@ export class ResponseOptions {
|
|||||||
*/
|
*/
|
||||||
type: ResponseType|null;
|
type: ResponseType|null;
|
||||||
url: string|null;
|
url: string|null;
|
||||||
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
|
constructor(opts: ResponseOptionsArgs = {}) {
|
||||||
|
const {body, status, headers, statusText, type, url} = opts;
|
||||||
this.body = body != null ? body : null;
|
this.body = body != null ? body : null;
|
||||||
this.status = status != null ? status : null;
|
this.status = status != null ? status : null;
|
||||||
this.headers = headers != null ? headers : null;
|
this.headers = headers != null ? headers : null;
|
||||||
|
4
tools/public_api_guard/http/http.d.ts
vendored
4
tools/public_api_guard/http/http.d.ts
vendored
@ -144,7 +144,7 @@ export declare class RequestOptions {
|
|||||||
/** @deprecated */ search: URLSearchParams;
|
/** @deprecated */ search: URLSearchParams;
|
||||||
url: string | null;
|
url: string | null;
|
||||||
withCredentials: boolean | null;
|
withCredentials: boolean | null;
|
||||||
constructor({method, headers, body, url, search, params, withCredentials, responseType}?: RequestOptionsArgs);
|
constructor(opts?: RequestOptionsArgs);
|
||||||
merge(options?: RequestOptionsArgs): RequestOptions;
|
merge(options?: RequestOptionsArgs): RequestOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ export declare class ResponseOptions {
|
|||||||
headers: Headers | null;
|
headers: Headers | null;
|
||||||
status: number | null;
|
status: number | null;
|
||||||
url: string | null;
|
url: string | null;
|
||||||
constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs);
|
constructor(opts?: ResponseOptionsArgs);
|
||||||
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user