title: How to call object function from Typescript object
body: <p>I'm trying to call a function on a Date object from TypeScript, but it won't allow me to. I'm doing this in an an if/else and I've eliminated the other two allowed primitive types. I just don't know how to use the object type from TypeScript. None of the functions available on the TypeScript object seems to be appropriate.
  Here's the code:</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>const formatDate = (date: string | number | object): string | null =&gt; {
      if (typeof date === 'string') return date ? new Date(date).toISOString() : null;
      else if (typeof date == 'number') return date != null ? new Date(date).toISOString() : null;
      else if (date.hasOwnProperty('toISOString')) return date.toISOString();
      else return null;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get the error:</p>
  
  <pre><code>TS2339: Property 'toISOString' does not exist on type 'object'.   
  </code></pre>
  
  <p>Is there any way to call an object's function from Typescript object?</p>