title: Typescript generic type T toString
body: <p>I don't think is possible but it's worth asking.
  In a generic method or class, I would like to log the name of the generic T type that has been used, I need it as string.</p>
  
  <p>Imagine a method like this:</p>
  
  <pre><code>static getTypeName&lt;T&gt;(): string {
      return typeof T; // This is wrong
  }
  </code></pre>
  
  <p>I would expect to be able to use it this way:</p>
  
  <pre><code>let m = getTypeName&lt;Message&gt;(); // Expected string "Message"
  let p = getTypeName&lt;Person&gt;();  // Expected string "Person"
  </code></pre>
  
  <p>The above <strong>getTypeName</strong> is wrong, it won't even build.
  typeof would be transpiled in JS and wouldn't produce the desired effect.
  I tried various things but with no success.</p>
  
  <p>Is there any way to actually do it?</p>
  
  <p>EDIT: Why this is not a duplicate of: <a href="https://stackoverflow.com/questions/41160690/is-it-possible-to-get-the-type-name-of-a-generic-type">this question</a></p>
  
  <p>The question and the example code shows how to get back an object and not the name of the type specified.
  Also the method is not generic because if you try to pass in a Type that has constructor parameters it will show the error:
  "<em>[ts] Argument of type 'typeof MyType' is not assignable to parameter of type 'new () => MyType'.</em>"
  Moreover, if you use the function within a generic method you cannot use T as parameter, this means that everywhere I would need to get the name from the generic Type, I would need to add the ctor to the parameters.</p>