[typescript-rxjs] restore prototype inheritance for clone & its clients (#6001)

* [typescript-rxjs] restore prototype inhertance

- previously clone() and its clients in the BaseAPI class were generic
- with removal of the generic argument, these methods became unavailable
  to the API classes inheriting from BaseAPI
- original generic was imprecise, as these are not statics
- return type of `this` is the correct notation

* [typescript-rxjs] Chery-pick from #5465 by @denyo

  - this is done to prevent the changes slated for 5.0 from conflicting
  - apply destructuring changes from
      - denyo:feature/rxjs-statuscode-and-progress@673d67c
This commit is contained in:
Ermolay Romanov 2020-05-19 04:06:08 -04:00 committed by GitHub
parent d92b8833b0
commit 2f9aa282e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 20 deletions

View File

@ -35,7 +35,7 @@ export class Configuration {
}
get apiKey(): ((name: string) => string) | undefined {
const apiKey = this.configuration.apiKey;
const { apiKey } = this.configuration;
if (!apiKey) {
return undefined;
}
@ -43,7 +43,7 @@ export class Configuration {
}
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
const accessToken = this.configuration.accessToken;
const { accessToken } = this.configuration;
if (!accessToken) {
return undefined;
}
@ -61,7 +61,7 @@ export class BaseAPI {
this.middleware = configuration.middleware;
}
withMiddleware = (middlewares: Middleware[]) => {
withMiddleware = (middlewares: Middleware[]): this => {
const next = this.clone();
next.middleware = next.middleware.concat(middlewares);
return next;
@ -121,7 +121,7 @@ export class BaseAPI {
* Create a shallow clone of `this` by constructing a new instance
* and then shallow cloning data members.
*/
private clone = (): BaseAPI =>
private clone = (): this =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}

View File

@ -46,7 +46,7 @@ export class Configuration {
}
get apiKey(): ((name: string) => string) | undefined {
const apiKey = this.configuration.apiKey;
const { apiKey } = this.configuration;
if (!apiKey) {
return undefined;
}
@ -54,7 +54,7 @@ export class Configuration {
}
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
const accessToken = this.configuration.accessToken;
const { accessToken } = this.configuration;
if (!accessToken) {
return undefined;
}
@ -72,7 +72,7 @@ export class BaseAPI {
this.middleware = configuration.middleware;
}
withMiddleware = (middlewares: Middleware[]) => {
withMiddleware = (middlewares: Middleware[]): this => {
const next = this.clone();
next.middleware = next.middleware.concat(middlewares);
return next;
@ -132,7 +132,7 @@ export class BaseAPI {
* Create a shallow clone of `this` by constructing a new instance
* and then shallow cloning data members.
*/
private clone = (): BaseAPI =>
private clone = (): this =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}

View File

@ -46,7 +46,7 @@ export class Configuration {
}
get apiKey(): ((name: string) => string) | undefined {
const apiKey = this.configuration.apiKey;
const { apiKey } = this.configuration;
if (!apiKey) {
return undefined;
}
@ -54,7 +54,7 @@ export class Configuration {
}
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
const accessToken = this.configuration.accessToken;
const { accessToken } = this.configuration;
if (!accessToken) {
return undefined;
}
@ -72,7 +72,7 @@ export class BaseAPI {
this.middleware = configuration.middleware;
}
withMiddleware = (middlewares: Middleware[]) => {
withMiddleware = (middlewares: Middleware[]): this => {
const next = this.clone();
next.middleware = next.middleware.concat(middlewares);
return next;
@ -132,7 +132,7 @@ export class BaseAPI {
* Create a shallow clone of `this` by constructing a new instance
* and then shallow cloning data members.
*/
private clone = (): BaseAPI =>
private clone = (): this =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}

View File

@ -46,7 +46,7 @@ export class Configuration {
}
get apiKey(): ((name: string) => string) | undefined {
const apiKey = this.configuration.apiKey;
const { apiKey } = this.configuration;
if (!apiKey) {
return undefined;
}
@ -54,7 +54,7 @@ export class Configuration {
}
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
const accessToken = this.configuration.accessToken;
const { accessToken } = this.configuration;
if (!accessToken) {
return undefined;
}
@ -72,7 +72,7 @@ export class BaseAPI {
this.middleware = configuration.middleware;
}
withMiddleware = (middlewares: Middleware[]) => {
withMiddleware = (middlewares: Middleware[]): this => {
const next = this.clone();
next.middleware = next.middleware.concat(middlewares);
return next;
@ -132,7 +132,7 @@ export class BaseAPI {
* Create a shallow clone of `this` by constructing a new instance
* and then shallow cloning data members.
*/
private clone = (): BaseAPI =>
private clone = (): this =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}

View File

@ -46,7 +46,7 @@ export class Configuration {
}
get apiKey(): ((name: string) => string) | undefined {
const apiKey = this.configuration.apiKey;
const { apiKey } = this.configuration;
if (!apiKey) {
return undefined;
}
@ -54,7 +54,7 @@ export class Configuration {
}
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
const accessToken = this.configuration.accessToken;
const { accessToken } = this.configuration;
if (!accessToken) {
return undefined;
}
@ -72,7 +72,7 @@ export class BaseAPI {
this.middleware = configuration.middleware;
}
withMiddleware = (middlewares: Middleware[]) => {
withMiddleware = (middlewares: Middleware[]): this => {
const next = this.clone();
next.middleware = next.middleware.concat(middlewares);
return next;
@ -132,7 +132,7 @@ export class BaseAPI {
* Create a shallow clone of `this` by constructing a new instance
* and then shallow cloning data members.
*/
private clone = (): BaseAPI =>
private clone = (): this =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this);
}