TypeScript: casting HTMLElement

后端 未结 13 2247
我寻月下人不归
我寻月下人不归 2020-12-02 05:34

Does anyone know how to cast in TypeScript?

I\'m trying to do this:

var script:HTMLScriptElement = document.getElementsByName(\"script\")[0];
alert(s         


        
13条回答
  •  失恋的感觉
    2020-12-02 05:50

    Could be solved in the declaration file (lib.d.ts) if TypeScript would define HTMLCollection instead of NodeList as a return type.

    DOM4 also specifies this as the correct return type, but older DOM specifications are less clear.

    See also http://typescript.codeplex.com/workitem/252

提交回复
热议问题