Bug: Incorrect type definition of CleanupResult
Brought to you by:
tomkozak
Originally created by: xeladotbe
According to the type definition, CleanupResult should have a property “deletedCacheRequests”. The PrecacheController returns a CleanupResult in the activate function, but instead of the “deletedCacheRequests” property you get “deletedURLs”
Type Definition CleanupResult:
https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-precaching/src/_types.ts#L17
Implementation of activate Function:
https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-precaching/src/PrecacheController.ts#L267
Originally posted by: Ujjwaljain16
I looked into it in detail
There’s currently a mismatch between the declared type and the runtime behavior:
CleanupResult) exposesdeletedCacheRequestsPrecacheController.activate()) returnsdeletedURLsdeletedURLsSo at runtime, consumers receive
{ deletedURLs }, while TypeScript users are guided to usedeletedCacheRequests, which doesn’t exist in practice.From what I can see:
deletedURLsis the de facto API (used in tests and implementation)deletedCacheRequestsappears to be a stale/incorrect type definitiondeletedURLsis semantically more accurate (array of URL strings, not Request objects)Proposed fix (non-breaking)
To avoid breaking either JS or TS users:
deletedURLsas the canonical fielddeletedCacheRequestsas a deprecated alias (pointing to the same array)Example:
This: