我有一个角14.1.1应用程序配置的渐进Web应用程序。当使用以下代码时,我得到了'ServiceWorkerRegistration‘类型上不存在的错误属性'sync’。
navigator.serviceWorker.ready.then(registration => {
if (registration.sync) { //Error: Property 'sync' does not exist on type 'ServiceWorkerRegistration'.
// Background Sync is supported.
} else {
// Background Sync isn't supported.
}
});发布于 2022-10-28 08:34:21
自从背景同步是当前的草案。以来,这些类型还没有倒入类型记录中。
您必须创建自己的定义:
interface SyncManager {
getTags(): Promise<string[]>;
register(tag: string): Promise<void>;
}
declare global {
interface ServiceWorkerRegistration {
readonly sync: SyncManager;
}
interface SyncEvent extends ExtendableEvent {
readonly lastChance: boolean;
readonly tag: string;
}
interface ServiceWorkerGlobalScopeEventMap {
sync: SyncEvent;
}
}https://stackoverflow.com/questions/74232292
复制相似问题