我通过以下方式检查浏览器是否为:
function isBrowserIE() {
return window.document.documentMode;
}
Typescript引发错误:
错误TS2339:类型“文档”上不存在属性“ documentMode”。
这是由于在1.5版的打字稿编译器中所做的更改:
从Document类型中删除了属性documentMode,parentWindow,createEventObject
我如何摆脱错误?
您可以简单地将其添加到Document
界面中:
interface Document {
documentMode?: any;
}
function isBrowserIE() {
return window.document.documentMode;
}
如果使用模块,则需要使用全局扩充:
declare global {
interface Document {
documentMode?: any;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句