get indexedDb quota storage information

孤街浪徒 提交于 2020-01-02 05:40:14

问题


I have tried below code to get indexedDb quota storage information

navigator.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

It is not working and giving the following error.

Property 'webkitTemporaryStorage' does not exist on type 'Navigator'.

Can anyone provide solution for getting indexedDb quota storage information in typescript?


回答1:


The problem lays in missing TypeScript typing. You can consider this answer.

To solve the issue, one solution is to declare the variable of type any:

let nav: any = navigator;
nav.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

Another way is to extend the interface of Navigator

interface Navigator {
    webkitTemporaryStorage: {
        queryUsageAndQuota ;
    }
}


来源:https://stackoverflow.com/questions/47528131/get-indexeddb-quota-storage-information

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