mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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
3 changed files with 6 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ export class ResponseOptions {
|
|||
*/
|
||||
type: ResponseType|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.status = status != null ? status : 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;
|
||||
url: string | null;
|
||||
withCredentials: boolean | null;
|
||||
constructor({method, headers, body, url, search, params, withCredentials, responseType}?: RequestOptionsArgs);
|
||||
constructor(opts?: RequestOptionsArgs);
|
||||
merge(options?: RequestOptionsArgs): RequestOptions;
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ export declare class ResponseOptions {
|
|||
headers: Headers | null;
|
||||
status: number | null;
|
||||
url: string | null;
|
||||
constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs);
|
||||
constructor(opts?: ResponseOptionsArgs);
|
||||
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue