这里是hero.service.ts构造函数
@Injectable()
export class HeroService {
private _heroObserver: Observer<Hero>;
hero$: Observable<Hero>;
public errorMessage: string;
constructor (private http: Http) {
this.hero$ = new Observable((observer:any) => this._heroObserver = observer).share(); // line 29
}
它编译错误
[0] hero.service.ts(29,9): error TS2322: Type 'Observable<{}>' is
not assignable to type 'Observable<Hero>'.
[0] Type '{}' is not assignable to type 'Hero'.
[0] Property '_id' is missing in type '{}'.
提到的类型“{}”是什么以及如何修复它?
PS:这是在beta-16上。
答案 0 :(得分:2)
我认为这应该有效:
this.hero$ = new Observable<Hero>((observer:any) => this._heroObserver = observer).share(); // line 29