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
This commit is contained in:
owcs-solx 2020-04-18 05:10:08 +08:00 committed by GitHub
parent 9f76d795b2
commit 3ef8e1ec49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,9 +9,17 @@ export class Queue {
unshiftRequest(entry: QueueEntry): Promise<void>;
}
export interface QueueOnSyncEvent {
queue: Queue;
}
export interface QueueOnSyncHandler {
(options: QueueOnSyncEvent): void|Promise<void>;
}
export interface QueueOptions {
maxRetentionTime?: number;
onSync?: () => void;
onSync?: QueueOnSyncHandler;
}
export interface QueueEntry<Metadata = any> {