From 631beea812a0ad8e05037929a58f35bd9b2a33bc Mon Sep 17 00:00:00 2001 From: Igor Voronin Date: Mon, 31 Jan 2022 19:15:29 +0200 Subject: [PATCH] Remove TypeScript bracket type casting syntax (#3848) --- .../Templates/AngularClient.liquid | 12 +++++----- .../Templates/AngularJSClient.liquid | 2 +- .../Templates/AxiosClient.liquid | 2 +- ...nt.ProcessResponse.HandleStatusCode.liquid | 22 +++++++++---------- .../Client.ProcessResponse.Return.liquid | 20 ++++++++--------- .../Templates/Client.RequestBody.liquid | 2 +- .../Templates/Client.RequestUrl.liquid | 2 +- .../Templates/FetchClient.liquid | 4 ++-- .../Templates/File.Utilities.liquid | 4 ++-- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/AngularClient.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/AngularClient.liquid index aced4792d0..81db245a2d 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/AngularClient.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/AngularClient.liquid @@ -86,7 +86,7 @@ return this.http.request({% if Framework.Angular.UseHttpClient %}"{{ operation.HttpMethodLower }}", {% endif %}url_, options_).{% if Framework.UseRxJs6 %}pipe({% endif %}{{ Framework.RxJs.ObservableMergeMapMethod }}((response_ : any) => { {%- endif -%} {%- if UseTransformResultMethod -%} - return this.transformResult(url_, response_, (r) => this.process{{ operation.ActualOperationNameUpper }}(r)); + return this.transformResult(url_, response_, (r) => this.process{{ operation.ActualOperationNameUpper }}(r as any)); {%- else -%} return this.process{{ operation.ActualOperationNameUpper }}(response_); {%- endif -%} @@ -94,15 +94,15 @@ if (response_ instanceof {% if Framework.Angular.UseHttpClient %}HttpResponseBase{% else %}Response{% endif %}) { try { {%- if UseTransformResultMethod -%} - return this.transformResult(url_, response_, (r) => this.process{{ operation.ActualOperationNameUpper }}(r)); + return this.transformResult(url_, response_, (r) => this.process{{ operation.ActualOperationNameUpper }}(r as any)); {%- else -%} - return this.process{{ operation.ActualOperationNameUpper }}(response_); + return this.process{{ operation.ActualOperationNameUpper }}(response_ as any); {%- endif -%} } catch (e) { - return >{{ Framework.RxJs.ObservableThrowMethod }}(e); + return {{ Framework.RxJs.ObservableThrowMethod }}(e) as any as Observable<{{ operation.ResultType }}>; } } else - return >{{ Framework.RxJs.ObservableThrowMethod }}(response_); + return {{ Framework.RxJs.ObservableThrowMethod }}(response_) as any as Observable<{{ operation.ResultType }}>; }){% if Framework.UseRxJs6 %}){% endif %}; } @@ -111,7 +111,7 @@ {%- if Framework.Angular.UseHttpClient -%} const responseBlob = response instanceof HttpResponse ? response.body : - (response).error instanceof Blob ? (response).error : undefined; + (response as any).error instanceof Blob ? (response as any).error : undefined; {%- endif -%} {% template Client.ProcessResponse %} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/AngularJSClient.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/AngularJSClient.liquid index 7636aa519c..f4687bee83 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/AngularJSClient.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/AngularJSClient.liquid @@ -41,7 +41,7 @@ {% template Client.RequestBody %} {% endif -%} - var options_ = { + var options_: ng.IRequestConfig = { url: url_, method: "{{ operation.HttpMethodUpper | upcase }}", {% if operation.IsFile -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/AxiosClient.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/AxiosClient.liquid index 3b3396337a..a30984b406 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/AxiosClient.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/AxiosClient.liquid @@ -39,7 +39,7 @@ {% template Client.RequestBody %} {% endif -%} - let options_ = { + let options_: AxiosRequestConfig = { {% if operation.HasBody -%} data: content_, {% endif -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.HandleStatusCode.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.HandleStatusCode.liquid index 40d2a0f9e8..b3d61838e3 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.HandleStatusCode.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.HandleStatusCode.liquid @@ -10,7 +10,7 @@ const fileNameMatch = contentDisposition ? /filename[^;=\n]*=(?:(\\?['"])(.*?)\1 const fileName = fileNameMatch && fileNameMatch.length > 1 ? decodeURIComponent(fileNameMatch[fileNameMatch.length - 1]) : undefined; {% if operation.WrapResponse -%} {% if Framework.IsAngular -%} -return {{ Framework.RxJs.ObservableOfMethod }}(new {{ operation.ResponseClass }}(status, _headers, { fileName: fileName, data: {% if Framework.Angular.UseHttpClient %}responseBlob{% else %}response.blob(){% endif %}, status: status, headers: _headers })); +return {{ Framework.RxJs.ObservableOfMethod }}(new {{ operation.ResponseClass }}(status, _headers, { fileName: fileName, data: {% if Framework.Angular.UseHttpClient %}responseBlob as any{% else %}response.blob() as any{% endif %}, status: status, headers: _headers })); {% elsif Framework.IsAngularJS -%} return this.q.resolve(new {{ operation.ResponseClass }}(status, _headers, { fileName: fileName, status: status, data: new Blob([response.data]), headers: _headers })); {% elsif Framework.IsAxios -%} @@ -20,7 +20,7 @@ return response.blob().then(blob => { return new {{ operation.ResponseClass }}(s {% endif -%} {% else -%} {% if Framework.IsAngular -%} -return {{ Framework.RxJs.ObservableOfMethod }}({ fileName: fileName, data: {% if Framework.Angular.UseHttpClient %}responseBlob{% else %}response.blob(){% endif %}, status: status, headers: _headers }); +return {{ Framework.RxJs.ObservableOfMethod }}({ fileName: fileName, data: {% if Framework.Angular.UseHttpClient %}responseBlob as any{% else %}response.blob() as any{% endif %}, status: status, headers: _headers }); {% elsif Framework.IsAngularJS -%} return this.q.resolve({ fileName: fileName, status: status, data: new Blob([response.data]), headers: _headers }); {% elsif Framework.IsAxios -%} @@ -45,7 +45,7 @@ result{{ response.StatusCode }} = {% unless response.IsPlainText %}JSON.parse({% let resultData{{ response.StatusCode }} = _responseText === "" ? null : {% if response.IsPlainText %}_responseText{% else %}{% if operation.HandleReferences %}jsonParse{% else %}JSON.parse{% endif %}(_responseText, this.jsonParseReviver){% endif %}; {{ response.DataConversionCode }} {% else -%} -result{{ response.StatusCode }} = _responseText === "" ? null : <{{ response.Type }}>{% if response.IsPlainText %}_responseText{% else %}{% if operation.HandleReferences %}jsonParse{% else %}JSON.parse{% endif %}(_responseText, this.jsonParseReviver){% endif %}; +result{{ response.StatusCode }} = _responseText === "" ? null : {% if response.IsPlainText %}_responseText{% else %}{% if operation.HandleReferences %}jsonParse{% else %}JSON.parse{% endif %}(_responseText, this.jsonParseReviver){% endif %} as {{ response.Type }}; {% endif -%} {% endif -%} {% if response.IsSuccess -%} @@ -76,25 +76,25 @@ return throwException({% if Framework.IsAngularJS %}this.q, {% endif %}"{{ respo {% elsif response.IsSuccess -%} {% if operation.WrapResponse -%} {% if Framework.IsAngular -%} -return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% elsif Framework.IsAngularJS -%} -return this.q.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return this.q.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% elsif Framework.IsAxios -%} -return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResultType }}(status, _headers, null)); +return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResultType }}(status, _headers, null as any)); {% else -%} -return new {{ operation.ResponseClass }}(status, _headers, null); +return new {{ operation.ResponseClass }}(status, _headers, null as any); {% endif -%} {% else -%} {% if Framework.IsAngular -%} {% if Framework.UseRxJs7 -%} -return {{ Framework.RxJs.ObservableOfMethod }}(null); +return {{ Framework.RxJs.ObservableOfMethod }}(null as any); {% else -%} -return {{ Framework.RxJs.ObservableOfMethod }}<{{operation.ResultType}}>(null); +return {{ Framework.RxJs.ObservableOfMethod }}<{{operation.ResultType}}>(null as any); {% endif -%} {% elsif Framework.IsAngularJS -%} -return this.q.resolve<{{ operation.ResultType }}>(null); +return this.q.resolve<{{ operation.ResultType }}>(null as any); {% elsif Framework.IsAxios -%} -return Promise.resolve<{{ operation.ResultType }}>(null); +return Promise.resolve<{{ operation.ResultType }}>(null as any); {% else -%} return{% if operation.HasResultType %} null{% endif %}; {% endif -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.Return.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.Return.liquid index 13fa1b0ada..a78fe6e9ac 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.Return.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.Return.liquid @@ -1,34 +1,34 @@ {% if Framework.IsFetchOrAurelia -%} {% if operation.WrapResponse -%} -return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% else -%} -return Promise.resolve<{{ operation.ResultType }}>(null); +return Promise.resolve<{{ operation.ResultType }}>(null as any); {% endif -%} {% elsif Framework.IsAxios -%} {% if operation.WrapResponse -%} -return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return Promise.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% else -%} -return Promise.resolve<{{ operation.ResultType }}>(null); +return Promise.resolve<{{ operation.ResultType }}>(null as any); {% endif -%} {% elsif Framework.IsAngular -%} {% if operation.WrapResponse -%} -return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% else -%} {% if Framework.UseRxJs7 -%} -return {{ Framework.RxJs.ObservableOfMethod }}(null); +return {{ Framework.RxJs.ObservableOfMethod }}(null as any); {% else -%} -return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(null); +return {{ Framework.RxJs.ObservableOfMethod }}<{{ operation.ResultType }}>(null as any); {% endif -%} {% endif -%} {% elsif Framework.IsAngularJS -%} {% if operation.WrapResponse -%} -return this.q.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null)); +return this.q.resolve<{{ operation.ResultType }}>(new {{ operation.ResponseClass }}(status, _headers, null as any)); {% else -%} -return this.q.resolve<{{ operation.ResultType }}>(null); +return this.q.resolve<{{ operation.ResultType }}>(null as any); {% endif -%} {% else -%} {% if operation.WrapResponse -%} -return new {{ operation.ResponseClass }}(status, _headers, null); +return new {{ operation.ResponseClass }}(status, _headers, null as any); {% else -%} return{% if operation.HasResultType %} null{% endif %}; {% endif -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestBody.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestBody.liquid index be64a59c97..5237b6bdbc 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestBody.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestBody.liquid @@ -27,7 +27,7 @@ else if ({{ parameter.VariableName }} !== undefined) {{ parameter.VariableName }} && {{ parameter.VariableName }}.forEach((item_, index_) => { for (let attr_ in item_) { if (item_.hasOwnProperty(attr_)) { - content_ += encodeURIComponent("{{ parameter.Name }}[" + index_ + "]." + attr_) + "=" + encodeURIComponent("" + (item_)[attr_]) + "&"; + content_ += encodeURIComponent("{{ parameter.Name }}[" + index_ + "]." + attr_) + "=" + encodeURIComponent("" + (item_ as any)[attr_]) + "&"; } } }); diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestUrl.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestUrl.liquid index 5363775df2..565f521d67 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestUrl.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/Client.RequestUrl.liquid @@ -46,7 +46,7 @@ else if ({{ parameter.VariableName }} !== undefined) {{ parameter.VariableName }} && {{ parameter.VariableName }}.forEach((item, index) => { for (let attr in item) if (item.hasOwnProperty(attr)) { - url_ += "{{ parameter.Name }}[" + index + "]." + attr + "=" + encodeURIComponent("" + (item)[attr]) + "&"; + url_ += "{{ parameter.Name }}[" + index + "]." + attr + "=" + encodeURIComponent("" + (item as any)[attr]) + "&"; } }); {% elsif parameter.IsDateOrDateTime -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/FetchClient.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/FetchClient.liquid index 7c4fb757b3..84e3cddc2a 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/FetchClient.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/FetchClient.liquid @@ -21,7 +21,7 @@ {%- if HasBaseClass -%} super({% if HasConfigurationClass %}configuration{% endif %}); {%- endif -%} - this.http = http ? http : window; + this.http = http ? http : window as any; {%- if UseGetBaseUrlMethod -%} this.baseUrl = this.getBaseUrl("{{ BaseUrl }}", baseUrl); {%- else -%} @@ -43,7 +43,7 @@ {% template Client.RequestBody %} {%- endif -%} - let options_ = { + let options_: RequestInit = { {%- if operation.HasBody -%} body: content_, {%- endif -%} diff --git a/src/NSwag.CodeGeneration.TypeScript/Templates/File.Utilities.liquid b/src/NSwag.CodeGeneration.TypeScript/Templates/File.Utilities.liquid index 14f8a8377d..ec54df72a2 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Templates/File.Utilities.liquid +++ b/src/NSwag.CodeGeneration.TypeScript/Templates/File.Utilities.liquid @@ -45,7 +45,7 @@ function blobToText(blob: any): Observable { } else { let reader = new FileReader(); reader.onload = event => { - observer.next((event.target).result); + observer.next((event.target as any).result); observer.complete(); }; reader.readAsText(blob); @@ -57,7 +57,7 @@ function blobToText(blob: any): Observable { function blobToText(blob: Blob, q: ng.IQService): ng.IPromise { return new q((resolve) => { let reader = new FileReader(); - reader.onload = event => resolve((event.target).result); + reader.onload = event => resolve((event.target as any).result); reader.readAsText(blob); }); }