属性“存储"在类型“导航器"上不存在

属性“存储

问题描述:

我正在尝试通过以下命令行从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;
    };
  }
}