2

I am getting an error of

Argument of type 'ActivatedRoute' is not assignable to parameter of type 'ActivatedRoute'.

Types of property 'url' are incompatible. Type 'Observable' is not assignable to type 'Observable'. Two different types with this name exist, but they are unrelated. Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'.

my typescript is as follows...I am getting error in navigateToList()

import { Component, ViewChild, OnInit } from '@angular/core'
import { Router, ActivatedRoute } from '@angular/router'
import { getParentRoute } from 'PwcLib/common'
import { ValidatorsService } from 'PwcLib/core-services'
import { ValidationForm } from 'PwcLib/validation'
import { CanDeactivateComponent } from 'PwcLib/routing'
import { UsersSyncService } from '../users.service'
import { User } from '../user'

@Component({
// define a templateUrl for component
templateUrl: 'user-details.component.html'
})
export class UserDetailsComponent implements OnInit, CanDeactivateComponent
{
user: User;
userId: number;
@ViewChild(ValidationForm) form: ValidationForm;

constructor(
    private usersSyncService: UsersSyncService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private validators: ValidatorsService
) {

}

ngOnInit() {
    //ngOnInit is not executed on parameters change so supscribe to params
    this.activatedRoute.params.forEach((params) => {
        let userIdParam = parseInt(params['userId']);
        this.userId = isNaN(userIdParam) ? 0 : userIdParam;
        if (this.userId == 0) {
            this.user = <User>{};
        } else {
            this.user = this.usersSyncService.getUser(this.userId);
            if (!this.user) {
                this.navigateToList();
            }
        }
    });
}

canDeactivate() {
    if (!this.form) return true;

    return this.form.allowNavigation();
}

private navigateToList() {
    // ../ navigates one level up in route but route can have few parts like /details/:id so getParentRoute utility is used to get parent route
    this.router.navigate(['./'], { relativeTo: getParentRoute(this.activatedRoute) });
}
}
Ishan Malik
  • 139
  • 3
  • 12
  • 1
    I get message `Argument of type 'ActivatedRoute' is not assignable to parameter of type 'ActivatedRoute'. Types of property 'url' are incompatible. Type 'Observable is not assignable to type 'Observable'` Notice the `Observable`. Even though my message is a bit different, I think the root cause is the same for you and me, and maybe the root cause is related to [this issue](http://stackoverflow.com/q/38168581/1175496) with the message `'Observable' is not a class derived from 'Observable'` In other words, I think Observable may be root cause. – Nate Anderson Apr 20 '17 at 20:00
  • The issue I linked also suspects `npm link` may cause the problem. OP (Ishan Malik) did not say if he is `npm link`ing here, so maybe my problem is completely unrelated to Ishan's post. But here's [one more GitHub link that may help](https://github.com/angular/angular/issues/11801#issuecomment-248704212) – Nate Anderson Apr 20 '17 at 22:52

0 Answers0