title: Typescript: how to get function name as string without TS2339 error
body: <p>I found the following example in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name" rel="nofollow noreferrer">Function.name documentation</a></p>
  
  <pre><code>const o = {
    foo(){}
  };
  o.foo.name; // "foo";
  </code></pre>
  
  <p>The problem in typescript (typed here):</p>
  
  <pre><code>    const o: { foo: () =&gt; void } = {
          foo: () =&gt; {
          }
      };
      o.foo.name;
  </code></pre>
  
  <p>comes when I want to retrieve 
  <code>o.foo.name</code>, where I will get an error </p>
  
  <blockquote>
    <p>TS2339 (property "name" does not exist)</p>
  </blockquote>
  
  <p>How can I deal with it, keeping the object typing?
  I want to avoid having to cast the property "foo" like <code>(&lt;any&gt;o.foo).name</code></p>
  
  <p>PS: The use case is to keep the typing for further refactoring. For instance the following is safe to be refactored:</p>
  
  <pre><code>spyOn(o, (&lt;any&gt;o.foo).name)
  </code></pre>
  
  <p>While this one is not</p>
  
  <pre><code>spyOn(o, "foo")
  </code></pre>
  
  <p>PS 2: It seems retrieving function name could be problematic on ts: <a href="https://stackoverflow.com/questions/37341729/get-name-of-function-in-typescript">Get name of function in typescript</a></p>