Я не понимаю, что не так с этим кодом, не могли бы вы мне помочь, пожалуйста?
import { Injectable } from '@angular/core';
import {
HttpEvent, HttpInterceptor, HttpHandler, HttpRequest
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';
import { AuthenticationSharedStorage } from '../storages/authentication.storage';
import { AuthenticationToken } from '../../models/authentication.model';
@Injectable()
export class AuthenticationInterceptor implements HttpInterceptor {
constructor(private storage: AuthenticationSharedStorage) {}
intercept(req: HttpRequest<any>, next: HttpHandler) {
this.storage.getData()
.pipe(
switchMap((data:AuthenticationToken )=> {
if(data){
const authToken = data.token;
const authReq = req.clone({ setHeaders: { Authorization: authToken } });
return next.handle(authReq);
}
return next.handle(req);
})
);
}
}
Полная ошибка:
Свойство «перехват» в типе «AuthenticationInterceptor» нельзя присвоить тому же свойству в базовом типе «HttpInterceptor». Введите '(req: HttpRequest, next: HttpHandler) => void' не назначается типу '(req: HttpRequest, next: HttpHandler) => Observable>'. Тип void нельзя присвоить типу Observable>. 16: 3