属性 'storage' 在类型 'Navigator' 上不存在
Property 'storage' does not exist on type 'Navigator'
我正在尝试使用此命令行从 Angular2 组件获取配额存储信息:
navigator.storage.estimate().then((data) => console.log(data));
该命令在纯 Javascript 脚本中正常运行,但在 Angular2/Typescript 中无法编译。
你能帮帮我吗?
谢谢
什么是导航器?我猜它是 window 上的一个没有任何类型的全局变量,所以你应该为这个
添加一个输入条目
我遇到了同样的问题,我找不到任何可用的 @types for the StorageManager 界面。
我的临时解决方案是在我的代码中手动声明它。
declare global {
interface StorageEstimate {
quota: number;
usage: number;
}
interface Navigator {
storage: {
estimate: () => Promise<StorageEstimate>;
persist: () => boolean;
persisted: () => boolean;
};
}
}
我正在尝试使用此命令行从 Angular2 组件获取配额存储信息:
navigator.storage.estimate().then((data) => console.log(data));
该命令在纯 Javascript 脚本中正常运行,但在 Angular2/Typescript 中无法编译。
你能帮帮我吗?
谢谢
什么是导航器?我猜它是 window 上的一个没有任何类型的全局变量,所以你应该为这个
添加一个输入条目我遇到了同样的问题,我找不到任何可用的 @types for the StorageManager 界面。
我的临时解决方案是在我的代码中手动声明它。
declare global {
interface StorageEstimate {
quota: number;
usage: number;
}
interface Navigator {
storage: {
estimate: () => Promise<StorageEstimate>;
persist: () => boolean;
persisted: () => boolean;
};
}
}