TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

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

Open avalanche1 opened this issue 5 years ago • 3 comments

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

avalanche1 avatar Feb 16 '21 11:02 avalanche1

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

HolgerJeromin avatar Feb 17 '21 08:02 HolgerJeromin

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

mutations.forEach({ target }) => {
  if (target instanceof HTMLElement) {
    console.log(target.classList);
  }
});

instil-spencerc avatar Sep 19 '22 22:09 instil-spencerc

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

avalanche1 avatar Oct 03 '22 12:10 avalanche1