2
私はobservablesとtypescriptを初めて使用しています。ここに私の認証コンポーネントはangular2Angular2認証 - タイプ 'AsyncSubject <{}>'をタイプ 'AsyncSubjectに割り当てることができません。<boolean> - observablesとtypescript
// route-protection.service.ts
import {Injectable} from '@angular/core';
import {
CanActivate,
Router,
ActivatedRouteSnapshot,
RouterStateSnapshot
} from '@angular/router';
import {Observable} from 'rxjs';
/*
* Shared Utilities
*/
import {Authentication} from './authentication.service';
import {Logging} from '../../app-components/common/utility';
@Injectable()
export class RouteProtection implements CanActivate {
constructor(private authService:Authentication,
private router:Router) {
}
canActivate(next:ActivatedRouteSnapshot, state:RouterStateSnapshot):boolean {
return this.authService.checkAuth()
.map(e=> {
if (e) {
return true;
}
}).catch(()=> {
this.router.navigate(['/about'])
return Observable.of(false)
})
}
}
のためだ。しかし、私はこのエラーを取得する:
[default] ~/src/app-components/common/route-protection.service.ts:20:3
Type 'AsyncSubject<{}>' is not assignable to type 'AsyncSubject<boolean>'.
Type '{}' is not assignable to type 'boolean'.
[default] ~/src/app-components/common/route-protection.service.ts:29:12
Type 'Observable<boolean>' is not assignable to type 'boolean'.
それが何を意味するのでしょうか?私はangular2を使用してルート保護を追加しようとしているので、ルートは認証が完了した後にしか起動できません。
おかげで男を返す
ですそれを修正した。 typescriptコンパイルエラーはこれ以上ありません。 – TetraDev