Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Observable<{}>' is not assignable to type 'Observable<boolean> | boolean '

Im trying to follow this tutorial, but I'm getting errors.

  1. pathMatch: 'full'. I tried changing "@angular/router" to "3.0.0-beta.2", still the same issue.

My dependencies:

"dependencies": {
    "@angular/common": "2.0.0-rc.3",
    "@angular/compiler": "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.3",
    "@angular/http": "2.0.0-rc.3",
    "@angular/platform-browser": "2.0.0-rc.3",
    "@angular/platform-browser-dynamic": "2.0.0-rc.3",
    "@angular/platform-server": "2.0.0-rc.3",
    "@angular/router": "3.0.0-beta.2",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "nativescript-angular": "0.2.0",
    "tns-core-modules": "^2.1.0"
},
  1. Type 'Observable<{}>' is not assignable to type 'Observable', where it points to the line 'return o';

    canDeactivate(): Observable<boolean> | boolean {
    
    if (!this.crisis || this.crisis.name === this.editName) {
    
    return true;
    }
    let p = this.dialogService.confirm('Discard changes?');
    let o = Observable.fromPromise(p);
    return o;
    }
    

Can anyone guide me to fix these errors? thanks.

like image 540
kenkulan Avatar asked Jul 11 '16 05:07

kenkulan


1 Answers

You could try casting:

canDeactivate(): Observable<boolean> | boolean {

    if (!this.crisis || this.crisis.name === this.editName) {

        return true;
    }
    let p = this.dialogService.confirm('Discard changes?');
    let o = <Observable<boolean>>Observable.fromPromise(p);
    return o;
}
like image 50
rinukkusu Avatar answered Sep 19 '22 19:09

rinukkusu