代码之家  ›  专栏  ›  技术社区  ›  kamalav

获取indexedDb配额存储信息

  •  4
  • kamalav  · 技术社区  · 7 年前

    我尝试了以下代码来获取indexedDb配额存储信息

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

    它不工作,并出现以下错误。

    类型“Navigator”上不存在属性“webkitTemporaryStorage”。

    有人能提供在typescript中获取indexedDb配额存储信息的解决方案吗?

    1 回复  |  直到 7 年前
        1
  •  9
  •   edkeveked    7 年前

    问题在于缺少TypeScript键入。你可以考虑一下 answer .

    为了解决这个问题,一种解决方案是声明类型为的变量 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);  }
    ); 
    

    另一种方法是扩展Navigator的界面

    interface Navigator {
        webkitTemporaryStorage: {
            queryUsageAndQuota ;
        }
    }