属性“存储"在类型“导航器"上不存在 [英] Property 'storage' does not exist on type 'Navigator'
本文介绍了属性“存储"在类型“导航器"上不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过以下命令行从Angular2组件中获取配额存储信息:
I'm trying to get the quota storage information from an Angular2 component with this command line:
navigator.storage.estimate().then((data) => console.log(data));
该命令在纯Javascript脚本中可以正常运行,但无法在Angular2/Typescript中进行编译.
The command works properly in a pure Javascript script but it doesn't get compiled in Angular2/Typescript.
你能帮我吗?
谢谢
推荐答案
我遇到了同样的问题,但是找不到任何可用的@类型"rel =" nofollow noreferrer> StorageManager 界面.
I had the same problem and I couldn't find any available @types for the StorageManager interface.
我的临时解决方案是在我的代码中手动声明它.
My temporary solutions was to manually declare it in my code.
declare global {
interface StorageEstimate {
quota: number;
usage: number;
}
interface Navigator {
storage: {
estimate: () => Promise<StorageEstimate>;
persist: () => boolean;
persisted: () => boolean;
};
}
}
这篇关于属性“存储"在类型“导航器"上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文