title: Why Typescript can't infer type when you assign a return typed method's output to a variable?
body: <p>I have a reusable service so I have created a public API with documentation and types to ease the usage of clients.</p>
  <pre class="lang-js prettyprint-override"><code>interface Storable {
    setItem(key: string, value: string): any;
    getItem(key: string): string;
    removeItem(key: string): any;
  }
  
  @Injectable({
    providedIn: 'root'
  })
  export class DataStorageService {
     private expirableSecureLocalStorage:any;
     private secureLocalStorage:any;
     private expirableLocalStorage:any;
     constructor(/*...*/) {
      this.expirableSecureLocalStorage = this.createExpirableStorage(this.createSecureStorage(localStorage));
      this.secureLocalStorage = this.createSecureStorage(localStorage);
      this.expirableLocalStorage = this.createExpirableStorage(localStorage);
     }
  
     /**
     * Returns a handle to localStorage: Use when you want to compose/decorate storages.
     */
    getLocalStore(): Storable {
      return localStorage;
    }
  
    /**
     * Returns a handle to sesionStorage: Use when you want to compose/decorate storages.
     */
    getSessionStore(): Storable {
      return sessionStorage;
    }
    /** 
     * Recommended: Singleton - prefer for ordinary operations
     */
    getExpirableSecureLocalStorage(): Storable {
      return this.expirableSecureLocalStorage;
    }
  
    /** 
     * Recommended: Singleton - prefer for ordinary operations
     */
    getSecureLocalStorage(): Storable {
      return this.secureLocalStorage;
    }
  
    /** 
     * Recommended: Singleton - prefer for ordinary operations
     */
    getExpirableLocalStorage(): Storable {
      return this.expirableLocalStorage;
    }
  
    //...
  
  }
  </code></pre>
  <p>Then in a client:</p>
  <pre class="lang-js prettyprint-override"><code>@Injectable({
    providedIn: 'root'
  })
  export class FeatureService {
  
    expirableSecureLocalStorage:any;
  
    constructor(private apiService: ApiService, private dataStorageService: DataStorageService) {  
      this.expirableSecureLocalStorage = dataStorageService.getExpirableSecureLocalStorage();                                 
    }
   
    async getFeatures(keyname: string) {
      let features: any;
      let feature: any;
      try {
        let featuresLocalData = this.expirableSecureLocalStorage.getItem(&quot;features&quot;);
        //...
      }
      //...
     }
  </code></pre>
  <p>When this code has evolved to current status, I have realized that when I have added the type <code>Storable</code> to <code>DataStorageService</code>, vscode's autocomplete/intellisense has started to suggest methods. However, in the client when I keep the method's <code>dataStorageService.getExpirableSecureLocalStorage()</code> which returns a <code>Storable</code> result in a reference variable <code>expirableSecureLocalStorage:any</code> and when I try to use a method of it like <code>getItem</code> as <code>this.expirableSecureLocalStorage.getItem(&quot;features&quot;)</code>, vscode does not offer <code>getItem</code> and other two methods directly.</p>
  <p>Why can't typescript infer the type of the reference variable which is assigned to the result of the method which has a return type?</p>
  <p>What should I have to do to make vscode suggest methods that is available?</p>