title: Handling typescript typings with eval
body: <p>I am trying to write a definition file for the <a href="http://npmjs.com/package/webworker-threads" rel="nofollow">webworker-threads</a> npm library. In their documentation it says that you can create a new worker as follows:</p>
  
  <pre><code>let worker = new Worker(function() {
    this.postMessage('worker created');
    this.close();
  });
  </code></pre>
  
  <p>The trick is that everything inside of that function that is used to construct the worker has access to the worker itself through a self variable. This is accomplished in their code by checking if the argument passed into <code>new Worker()</code> is a function, and if so calling eval on it. See <a href="https://github.com/audreyt/node-webworker-threads/blob/master/src/worker.js#L38" rel="nofollow">here</a>.</p>
  
  <p>I'm wondering how to duplicate this with my typings. So far I have this, but it doesn't work:</p>
  
  <pre><code>export class Worker {
      public onmessage: (event: any) =&gt; any;
  
      public thread: Thread;
  
      constructor(fn?: Worker | string); // &lt;= Doesn't work because technically the function passed in isn't a worker, it just accesses the new Worker as if it were.
  
      public postMessage(data: any): void;
  
      public terminate(): void;
  
      public addEventListener(type: string, cb: (event: any) =&gt; any): void;
  
      public removeEventListener(type: string): void;
  }
  </code></pre>