From 3ef8e1ec49822ffba328e1bbeec93943760f88e6 Mon Sep 17 00:00:00 2001 From: owcs-solx <56524422+owcs-solx@users.noreply.github.com> Date: Sat, 18 Apr 2020 05:10:08 +0800 Subject: [PATCH] Fix the signature for `onSync` for @types/workbox-background-sync (#43950) * Fix incorrect onSync type The type for onSync is incorrect. It should contain an argument containing the `queue` property. From the documentation for `workbox-background-sync:4.3.0`: ``` * @param {Function} [options.onSync] A function that gets invoked whenever * the 'sync' event fires. The function is invoked with an object * containing the `queue` property (referencing this instance), and you * can use the callback to customize the replay behavior of the queue. * When not set the `replayRequests()` method is called. * Note: if the replay fails after a sync event, make sure you throw an * error, so the browser knows to retry the sync event later. ``` * Extract callback as a new type Update definition in accordance to suggested changes by @JasonHK. For consistency sake, this is identical to https://github.com/GoogleChrome/workbox/blob/master/packages/workbox-background-sync/src/Queue.ts. * Fix test failures * Update as per suggestions by @JasonHK --- types/workbox-background-sync/Queue.d.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/types/workbox-background-sync/Queue.d.ts b/types/workbox-background-sync/Queue.d.ts index 67257dd4c9..462f01f894 100644 --- a/types/workbox-background-sync/Queue.d.ts +++ b/types/workbox-background-sync/Queue.d.ts @@ -9,9 +9,17 @@ export class Queue { unshiftRequest(entry: QueueEntry): Promise; } +export interface QueueOnSyncEvent { + queue: Queue; +} + +export interface QueueOnSyncHandler { + (options: QueueOnSyncEvent): void|Promise; +} + export interface QueueOptions { maxRetentionTime?: number; - onSync?: () => void; + onSync?: QueueOnSyncHandler; } export interface QueueEntry {