taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

HTMLElement class not compatible with typescript dom HTMLElement interface #179

Closed viceice closed 2 years ago

viceice commented 2 years ago

Currently the HTMLElement isn't compatible with the global HTMLElement from the dom lib from typescript. I'm not able to exclude the dom typings, because they are coming from a transitiv dependency

I would propose two solution:

  1. rename HTMLElement class to not iterfere with interface
  2. implement interface to be compatible
nonara commented 2 years ago

Hi @viceice! Thanks for the report.

Unfortunately, naming collisions will tend to happen when there are different implementations which define the same sort of thing (ie. Node). This is generally not an issue, but I understand that when global types are introduced, it can pose an issue with TypeScript.

In these cases, it's generally best practice to simply handle it the way that you have. Alternatively, you can also alias the type in the import statement.

Example: import { HTMLElement as NhpHTMLElement } from 'node-html-parser'

Hope that helps!

viceice commented 2 years ago

That don't help, as we can't use that import for esm modules 😕