microsoft / TypeScript-DOM-lib-generator

Tool for generating dom related TypeScript and JavaScript library files
Apache License 2.0
616 stars 418 forks source link

MutationRecord addedNodes & removedNodes should be typed as NodeList<Element> #981

Open avalanche1 opened 3 years ago

avalanche1 commented 3 years ago

In the spirit of https://github.com/microsoft/TypeScript/issues/38616 MutationRecord's addedNodes & removedNodes props should be typed as NodeList<Element>

In TS ^4.1.3 they are NodeList which gives me TS2339: Property 'classList' does not exist on type 'Node' error when trying to access one of its members' Element-related properties:

image

HolgerJeromin commented 3 years ago

But I get TextNodes with this API. This is more a problem with dynamic type change with the ?. operator.

instil-spencerc commented 2 years ago

I was able to get around this error by doing the following:

mutations.forEach({ target }) => {
  if (target instanceof HTMLElement) {
    console.log(target.classList);
  }
});
avalanche1 commented 1 year ago

@instil-spencerc cool but we need a fix, not a work around