打字稿编译错误:类型“节点"上不存在属性"classList" [英] Typescript compile error: Property 'classList' does not exist on type 'Node'

查看:192
本文介绍了打字稿编译错误:类型“节点"上不存在属性"classList"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 7 x64

Windows 7 x64

使用gulp-typescript 2.7.7和打字稿1.5 beta进行编译

Compiling using gulp-typescript 2.7.7 using typescript 1.5 beta

获取错误:由于声明,属性"classList"在节点"类型上不存在 document.getElementsByClassName('left-aside-wrapper')[0].classList.toggle('isOpen');

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

我看到在lib.d.ts文件中将classList定义为 interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode { classList: DOMTokenList;

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

不是所有人都熟悉d.ts文件的工作原理,这是我的错误,还是d.ts文件中的错误需要报告?

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?

推荐答案

这是因为getElementsByClassName被定义为返回Node数组而不是Element数组.

This is becuase getElementsByClassName is defined to return Node array and not an Element array.

不是所有人都熟悉d.ts文件的工作原理,这是我的错误还是d.ts文件中的错误需要报告

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

基于 https://developer.mozilla.org/zh-CN/docs/Web/API/Document/getElementsByClassName 我会将其报告为错误.

Based on https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName I would report it as an error.

这篇关于打字稿编译错误:类型“节点"上不存在属性"classList"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆