Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Authentication handlers should match Typescript interface #21

Open
singingwolfboy opened this issue Apr 10, 2020 · 0 comments
Open

Authentication handlers should match Typescript interface #21

singingwolfboy opened this issue Apr 10, 2020 · 0 comments

Comments

@singingwolfboy
Copy link

singingwolfboy commented Apr 10, 2020

The authentication handlers in auth.ts all define handleAuthentication methods that look like this:

handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs): Promise<ifm.IHttpClientResponse> {
    return null;
}

However, this is not strictly valid Typescript, since the actual return type does not match the declared return type. Notice that the actual return type is null, while the declared return type is Promise<ifm.IHttpClientResponse>.

Fixing this issue may require modifying the Typescript types to better describe intent. Here's one way we could do it:

export interface IRequestHandlerWithAuth {
  prepareRequest(options: http.RequestOptions): void;
  canHandleAuthentication(response: IHttpClientResponse): true;
  handleAuthentication(
    httpClient: IHttpClient,
    requestInfo: IRequestInfo,
    objs: any
  ): Promise<IHttpClientResponse>;
}

export interface IRequestHandlerWithoutAuth {
  prepareRequest(options: http.RequestOptions): void;
  canHandleAuthentication(response: IHttpClientResponse): false;
}

export type IRequestHandler =
  | IRequestHandlerWithAuth
  | IRequestHandlerWithoutAuth;

Notice how there are now two different kinds of authentication handlers: with and without auth. If a handler does not support authentication, it does not need to implement the handleAuthentication() method!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant