Rename symbol implicitly imported from internal library in TypeScript

I have a module where I'm using Element class implicitly imported from the "dom" internal library.

However, in the same module I want to define an Element class of my own. This of course leads to a name collision and a world of pain.

is there a way to rename the implicit Element class from the DOM library?

Ideally, I would like something like this:

import * as DOM from 'dom'; // <-- what do I write here?

class Element { // <-- my element
  private element: DOM.Element; // <-- reference to the original DOM element
}
728x90

1 Answers Rename symbol implicitly imported from internal library in TypeScript

The only solution I've found so far is to define a custom type pointing to the original DOM symbol:

type DOMElement = Element;

namespace Acme {

  class Element {
    private element: DOMElement;
  }

}

The idea here is to hide my custom Element class inside of a namespace and reference the DOM Element indirectly using custom type.

However, a better approach would be highly appreciated.

4 months ago