title: Extend external class prototype/type definition with custom function (Typescript)
body: <p>I'm trying to extend a class (from an external websocket library) with a custom function by adding my function to the prototype. But i'm get the <code>Property 'customFuction' does not exist on type 'WebSocket'</code> error which is understandable.</p>
  <pre class="lang-js prettyprint-override"><code>import WebSocket from &quot;ws&quot;;
  
  WebSocket.prototype.customFunction = function customFunction(): void {
                      ^^^^^^^^^^^^^^
  &quot;Property 'customFuction' does not exist on type 'WebSocket'
  };
  </code></pre>
  <p>But my question is how do I add my function to the existing class definition?<br />
  I don't want to create a new type (like <code>MyWebSocket extends WebSocket</code>) because I want the method to be available on the WebSocket class.</p>
  <hr />
  <p>Edit: I also tried the solution below suggested by @Balastrong but this still doesn't work. I'm also using the <code>@types/ws</code> package for the type definitions but I don't think module augmentation updates those definitions, could this be the reason for why this solution isn't working?</p>
  <pre class="lang-js prettyprint-override"><code>// WebSocketExtensions.ts
  import WebSocket from &quot;ws&quot;;
  
  declare module &quot;ws&quot; {
    export interface WebbSocket {
      customFunction(): void;
    }
  }
  
  WebSocket.prototype.customFunction = () =&gt; console.log('Hey');
  </code></pre>