Typescript compile error: Property 'classList' does not exist on type 'Node'

dan picture dan · Jun 29, 2015 · Viewed 13.8k times · Source

Windows 7 x64

Compiling using gulp-typescript 2.7.7 using typescript 1.5 beta

Getting error: Property 'classList' does not exist on type 'Node' because of statement document.getElementsByClassName('left-aside-wrapper')[0].classList.toggle('isOpen');

I see that classList is defined in the lib.d.ts file as interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode { classList: DOMTokenList;

Not all that familiar with how d.ts files work so is this my error or is it a bug in the d.ts file that need to be reported?

Answer

Emon picture Emon · Mar 27, 2020

I have got the same issue when I want to update the classList of the fist child.

And my solution is

const element = document.getElementById('testId').firstChild as HTMLElement;