title: how to declare a variable with two types via typescript
body: <p>I want to declare a variable with two types via ts.But the complier tips error.
  like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>interface IAnyPropObject { 
      [name: string]: any;
  }
  let a: IAnyPropObject | ((str: string) =&gt; any);
  a.B = "bbbbbbbb";//tips error
  a("");//tips error</code></pre>
  </div>
  </div>
  </p>
  
  <p>note:I don't want to use 'any' to declare.I just want to constraint the variable by this way only.Because of the code are so old and they are not TS code.</p>