我正在研究需要滚动位置的自定义指令。我发现所有主流浏览器都支持
window.scrollY
而IE11需要
document.documentElement.scrollTop
因此,我试图确定当前浏览器是否为IE11:
ngOnInit(){
this.isIE11 = !!window.MSInputMethodContext && !!document.documentMode;// tslint:disable-line
this.checkScrollPosition();
}
我得到ts错误的地方
property MSInputMethodContext doesnt exist on type Window
和
property documentMode doesnt exist on type Document
,尽管代码在我测试的所有浏览器(chorme、safari、ie11)中都能正常工作
1) 我认为这会很好,因为TS将被转换为纯JS,在那里可以访问这些属性,对吗?
2) 我是否应该抑制此警告(如何抑制?)或者我应该尝试不同的浏览器检测方法吗?
我尝试添加此内容,但目前没有成功:
//tslint:disable-line
//noinspection TypeScriptUnresolvedProperty