我有一个 TypeScript 项目(https://github.com/jmaister/excellentexport https://github.com/jmaister/excellentexport)并且工作正常。
添加dependabot进程后,建议升级typescript:
Bump typescript from 4.3.4 to 4.4.3
但是,由于我正在维护的库引用了 Internet Explorer 旧的 Internet Explorer 属性,因此无法使用新版本进行构建。
以下是构建错误的示例:
src/excellentexport.ts:143:30 - error TS2339: Property 'msSaveBlob' does not exist on type 'Navigator'.
143 if (window.navigator.msSaveBlob) {
~~~~~~~~~~
src/excellentexport.ts:145:30 - error TS2339: Property 'msSaveBlob' does not exist on type 'Navigator'.
145 window.navigator.msSaveBlob(blob, filename);
~~~~~~~~~~
src/excellentexport.ts:278:34 - error TS2339: Property 'msSaveBlob' does not exist on type 'Navigator'.
我应该删除对旧版 Internet Explorer 的支持吗?有办法继续使用那些 IE 特定属性吗?
我最近遇到了完全相同的问题,我找到的解决方案是扩展Navigator
界面中的global
命名空间所以它仍然包括msSaveBlob
,基于如何msSaveBlob
由 TypeScript 记录在此处:文件管理器 https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_dom_d_.msfilesaver.html#mssaveblob
这是我使用的代码:
declare global {
interface Navigator {
msSaveBlob?: (blob: any, defaultName?: string) => boolean
}
}
if (navigator.msSaveBlob) {
// use navigator.msSaveBlob
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)