gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

Cancelling request type #160

Closed gmq closed 7 years ago

gmq commented 7 years ago

The README mentions that returning false in an interceptor cancels the request but I'm getting the following typing error:

Argument of type '(data: any[], method: string) => false | any[]' is not assignable to parameter of type 'Interceptor<any[], any[] | Observable<any[]>>'.
  Type 'false | any[]' is not assignable to type 'any[] | Observable<any[]>'.
    Type 'false' is not assignable to type 'any[] | Observable<any[]>'.

with this piece of code:

httpInterceptor.request().addInterceptor((data, method) => {
        if (!auth.email || !auth.token) return false;
        const headers: Headers = getHttpHeadersOrInit(data, method);
        headers.set('X-User-Email', auth.email);
        headers.set('X-User-Token', auth.token);
        return data;
});

Any ideas about what I'm doing wrong? Thanks!

gund commented 7 years ago

Hey nice observation! According to this line the return type of interceptor function is defined as any[] | Observable<any[]> so there is no boolean.

That is basically why it complains =)

I will push the fix shortly

gmq commented 7 years ago

Wow, that was fast. Thanks!

gund commented 7 years ago

Fix landed in v3.1.2