How to implement BehaviorSubject with getter and setter in Angular 2
<p>I'm trying to implement in my LoginService a <code>isLoggedIn</code> boolean value of type <code>BehaviorSubject</code> together with getter and setter functions to get the value as an Observable / set the variable correctly via its BehaviorSubject. This is working, however it throws two errors in TSLint about "Type not assignable" and "Dublicate identifier". What would be the right way to define it without TSLint complaining about.</p>

<p>This is a stripped down version of the above mentioned code:</p>

<pre class="lang-js prettyprint-override"><code>@Injectable()
export class LoginService {
  public isLoggedInSource = new BehaviorSubject&lt;boolean&gt;(false);
  public isLoggedIn: Observable&lt;boolean&gt; = this.isLoggedInSource.asObservable(); // Duplicate identifier 'isLoggedIn'.

  constructor(private http: Http) {}

  set isLoggedIn(logged): void { // Duplicate identifier 'isLoggedIn'.
    this.isLoggedInSource.next(logged);
  }

  get isLoggedIn(): Observable&lt;boolean&gt; { // Duplicate identifier 'isLoggedIn'.
    return this.isLoggedInSource.asObservable();
  }

  logout() {
    this.isLoggedIn = false; // Type 'boolean' is not assignable to type 'Observable&lt;boolean&gt;'.
  }

  login(body) {
    return this.http.post('/login', body)
        .map(res =&gt; {
                if (res.token) {
                  this.isLoggedIn = true; // Type 'boolean' is not assignable to type 'Observable&lt;boolean&gt;'.
                }
                return res;
              })
        .catch(err =&gt; Observable.throw(err););
  }
}
</code></pre>