title: How can I extend a build class, like HTMLElement or Node, inside a typescript module?
body: <p>This code work in a typescript file:</p>
  
  <pre><code>interface Node {
      replaceWith(newnode): void;
  }
  
  Node.prototype.replaceWith = function(newnode: Node) {
      this.parentElement.replaceChild(newnode, this);
  };
  </code></pre>
  
  <p>It stops working as soon as the file becomes a module. So by adding this:</p>
  
  <pre><code>export let x = 42 // export statement turns the ts file into a module
  </code></pre>
  
  <p>the compiler complains: <em>Property 'replaceWith' does not exist on type</em>  'Node'. Why is this and how to work around?</p>
  
  <p>I understand that the extension must be declared in the global "scope" and the module is no longer global enough. But while in C++ for instance I can always add brackets around a block and make it global scope, in typescript I do not see a similar way.</p>