我不明白这段代码有什么问题,你能帮我吗?
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' 类型中的属性 'intercept' 不能分配给基类型 'HttpInterceptor' 中的相同属性。类型 '(req: HttpRequest, next: HttpHandler) => void' 不可分配给类型 '(req: HttpRequest, next: HttpHandler) => Observable>'。类型 'void' 不能分配给类型 'Observable>'。16:3