Property 'storage' does not exist on type 'Navigator'

拈花ヽ惹草 提交于 2019-12-10 11:25:24

问题


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));

The command works properly in a pure Javascript script but it doesn't get compiled in Angular2/Typescript.

Can you help me?

Thanks


回答1:


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;
    };
  }
}



回答2:


what is navigator ? I guess it is a global variable on window without any type, so you should add a typing entry for this

https://github.com/typings/typings



来源:https://stackoverflow.com/questions/46957270/property-storage-does-not-exist-on-type-navigator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!