title: Typescript: 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)
body: <p>The following is the code that works best for displaying custom errors in Chrome Devtools, Node.js, etc. Based on <a href="https://stackoverflow.com/a/24336262/7983596">this StackOverflow answer</a>.</p>
  
  <pre class="lang-js prettyprint-override"><code>function CustomErr (message) {
    var err = new Error(message)
    Object.setPrototypeOf(err, CustomErr.prototype)
    return err
  }
  
  CustomErr.prototype = Object.create(Error.prototype, {
    name: { value: 'Custom Error', enumerable: false }
  })
  </code></pre>
  
  <p>However, when I convert it to Typescript:</p>
  
  <pre><code>function CustomErr (message: string) {
    var err = new Error(message)
    Object.setPrototypeOf(err, CustomErr.prototype)
    return err
  }
  
  CustomErr.prototype = Object.create(Error.prototype, {
    name: { value: 'Custom Error', enumerable: false }
  })
  </code></pre>
  
  <p>Calling <code>throw new CustomErr("something went wrong")</code> shows this error:</p>
  
  <pre><code>'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)
  </code></pre>
  
  <p>What can I do to correctly type-annotate my code? If you can find another equivalent code solution, feel free to suggest it, but it MUST have the same behavior in Chrome DevTools (this alone of all solutions I tried displays a custom error name nicely). Thanks!</p>
  
  <p><strong>EDIT</strong>:
  Need to support older browsers, so I can't use ES6 classes. I'd prefer not to transpile classes to ES6 because I'm creating a lightweight library, and a class polyfill alone is 10% of my entire codesize.</p>
  
  <p>So to recap, how can I annotate the code I have now?</p>