title: Implementing instanceof checks for custom typescript Error instances?
body: <p>Typescript has this <a href="https://github.com/Microsoft/TypeScript/issues/13965" rel="noreferrer">instanceof checks on custom errors</a> issue, but it's not clear what we need to do to get <code>instanceof</code> working.  For example for this exception how would we get <code>instanceof</code> working:</p>
  
  <pre><code>    /**
       * @param message The error message
       * @param value The value that violates the constraint
       * @param field The name of the field
       * @param type The expected type for the field
       * @param constraint The name of the constraint violated
       * @param code The application or module code for the error
       */
      export class IsError extends Error {
        constructor(
          public message:string,
          public value: any, 
          public field?:string, 
          public type?: string,
          public constraint?: string,
          public code?:string) {
            super(message);
            this.name = 'IsError';
            Object.setPrototypeOf(this, IsError.prototype);      
        }
      }
  </code></pre>
  
  <p><a href="https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work" rel="noreferrer">This link says we can manually adjust the prototype</a>, which is what I'm doing, but this test is not passing:</p>
  
  <pre><code>it("should be an instance of IsError", () =&gt; {
     let error = new IsError("This is an IsError", 'value');
     expect(error instanceof IsError)).toBeTruthy();
  });
  </code></pre>
  
  <h2>Correction</h2>
  
  <p>I had an additional parenthesis in the test <code>...IsError))</code> that I mistook for the test not passing.  I updated the test and now it work.  So the example <code>IsError</code> implementation in this question is correct.</p>
  
  <p>IIUC this implementation will not not work in ES5, but AFAIK clients that include CoreJS will be ok.</p>