【发布时间】:2012-09-23 02:35:36
【问题描述】:
我正在尝试这样做:
var script:HTMLScriptElement = document.getElementsByName("script")[0];
alert(script.type);
但它给了我一个错误:
Cannot convert 'Node' to 'HTMLScriptElement': Type 'Node' is missing property 'defer' from type 'HTMLScriptElement'
(elementName: string) => NodeList
除非我将它转换为正确的类型,否则我无法访问脚本元素的“类型”成员,但我不知道如何执行此操作。我搜索了文档和示例,但找不到任何东西。
【问题讨论】:
-
请注意,这个转换问题在 0.9 中不再存在 - 请参阅下面@Steve 的回答。
-
@GregGum 我没有看到史蒂夫的回答
标签: typescript type-assertion typescript-types typescript-lib-dom