Q:

Eliminating subscribe(...) by returning string instead of Observable in Angular

I've been requested to investigate how to make a call to a service but return the final result instead of an observable.  In the service, there's a method like this. 
getToken(name: string, pass: string): string {
  const url = "https://localhost:44310/api/Security/login";
  const data = { name, pass };

  return this.http.post<any>(url, data);
}

In the component that will use it, we subscribe to it and consume whatever pops out from the result (or act on the error).  Now, I'd like to introduce a private field that will be read when invoking getToken(...) and returned if it's been assigned.  Otherwise, I'd like to do a POST and store the result, then return it. 
private token: string;

getToken(name: string, pass: string): string {
  if(this.token)
    return this.token;

  const url = "https://localhost:44310/api/Security/login";
  const data = { name, pass };

  this.http.post<any>(url, data)
    .subscribe(
      suc => this.token = suc,
      err => this.token = null);

  return this.token;
}

Now, this will obviously fail, because the asynchronously assigned value to this.token isn't there yet at the point of leaving the method.  I doubt that putting it into the success callback like this 
this.http.post<any>(url, data)
  .subscribe(
    suc => { this.token = suc; return this.token; }
    err => this.token = null);

will do any different.  At the moment I'm stuck and start to suspect that there's no way to return a fix, realized value eliminating the subscription in the component. 
Is there a way to introduce a field as described above? 
I've tried this post but it produced error: Property 'map' does not exist on type 'Observable'. 

A:

You shouldn't want to remove the observable from the call stack.   You haven't provided any reason to do so.   Observables are by far more useful in an async call stack which you have. 
It sounds like your actual problem is caching the result so the code doesn't make duplicate calls.   That's is very easy to do. 
private token: BehaviorSubject<string|null> = new BehaviorSubject<string|null>(null);
private token$ = this.token
  .asObservable()
  .pipe(filter((value) => value ! = null));

getToken(name: string, pass: string): observable<string> {

  const url = "https://localhost:44310/api/Security/login";
  const data = { name, pass };

  if (this.token.value == null) {
    this.http.post<any>(url, data)
      .subscribe(
        value => this.token.next(value),
        _ => this.token.next(null));
  }

  return this.token$;
}

Subscriber example:

  someObject.getToken(params)
    .subscribe(token => {
      // when token is available it will not be null. 
      // since the source is a BehaviorSubject, we get the last value
    }); 

note: make sure you unsubscribe if you aren't doing UI Pipe Async. 
Subject Reference:

My question is if it's possible to encapsulate it somehow and return a simple string (if assigned since before) or (otherwise, if the string hasn't been stored yet) return the async value after a while keeping the executing method in the component locked.  

Yes you theoretically could, but this is an absolutely terrible idea:
private token: string | null = null;
getToken(name: string, pass: string): string | observable<string>{

  if (this.token ! = null) {
    return token;
  }

  const url = "https://localhost:44310/api/Security/login";
  const data = { name, pass };

  return this.http.post<any>(url, data)
      .tap(value => this.token = value);
}

Now you've provided either a string or observable<string> which does exactly what you asked, however your consumers now have to jump through a ton of hoops to actually do what they need to do, and anyone who reads this is literally going to think WTF. 
subscriber:

   var result = someobject.getToken(params);
   if (result typeof 'string') {
     dosomethingwithstring(result);
   }
   else {
     result.subscribe(result2 => dosomethingwithstring(result));
   }

That's just a terrible pattern to leave other programmers with and even try to maintain.