Add Typescript type definitions for workbox-sw#1436
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
CLA has been signed |
|
CLAs look good, thanks! |
|
Also, just an fyi and to check if there is no collision between the two. The TS for workbox generateSW options is here: Polymer/polymer-build#309 |
|
@prateekbh There are no collisions between the two 😊. Your typings cover |
|
It's will be great! Any news about adding? |
|
I added typings for streams such that the typings fully support v3.2.0 |
|
Also, it would be cool if we could get an interface for custom plugins to implement that would have the type checking enabled. It would basically enforce that any plugins are of this shape: https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins |
|
Here are the plugin typings: // Custom type for Officehome
declare interface WorkboxPlugin {
readonly cacheWillUpdate?: (context: CacheWillUpdatePluginContext) => Response
readonly cacheDidUpdate?: (context: CacheDidUpdatePluginContext) => void;
readonly cachedResponseWillBeUsed?: (context: CacheResponseWillBeUsedPluginContext) => Response
readonly requestWillFetch?: (context: RequestWillFetchPluginContext) => Request;
readonly fetchDidFail?: (context: FetchDidFailPluginContext) => void;
};
interface CacheWillUpdatePluginContext {
readonly request: Request;
readonly response: Response;
}
interface CacheDidUpdatePluginContext {
readonly cacheName: string;
readonly request: Request;
readonly oldResponse: Response;
readonly newResponse: Response;
}
interface CacheResponseWillBeUsedPluginContext {
readonly cacheName: string;
readonly request: Request;
readonly matchOptions: any; // <-- What should this be? `object`?
readonly cachedResponse: Response;
}
interface RequestWillFetchPluginContext {
readonly request: Request;
}
interface FetchDidFailPluginContext {
readonly originalRequest: Request;
readonly request: Request;
readonly error: Error;
}Also, had to modify this type: type Plugin = BroadcastUpdatePlugin | RangeRequestsPlugin | CacheableResponsePlugin | BackgroundSyncPlugin | ExpirationPlugin | WorkboxPlugin; |
…ed typings for Custom Workbox plugins
|
@josephliccini Yes, you're right. I fixed the signature of I also added typings for Custom Workbox Plugins (Exported as a named export). Thanks for your typings! I corrected them a little bit ( |
|
Hey @wessberg looks like custom plugin callbacks that return values support returning you can see it used in the source here: and for workbox/packages/workbox-core/_private/fetchWrapper.mjs Lines 65 to 67 in 49ec72a So looks like we should update typings for custom plugins to support |
|
Hello @wessberg! First off, apologies for the delay in acting on this PR. After discussing it with the other current maintainers, we don't feel like we can commit to maintaining these typings over time. We appreciate the work you put into creating them to begin with, but stale typings seem inevitable as we make changes to the codebase given our lack of familiarity with TypeScript. I'm familiar enough with TypeScript to know that some folks submit "unofficial" Would you be willing to go that route? |
|
@josephliccini, I've updated the typings to support returning @jeffposnick, that is completely understandable 👍. I'll try to add the typings to DefinitelyTyped instead such that they can be installed from |
|
I'm going to close this PR in favor of the DefinitelyTyped approach. Once there's something published that you want us to link to, pass along the URL. |
|
@jeffposnick, the typings have been published now! |

R: @jeffposnick @addyosmani @gauntface
Fixes #1410
This PR adds Typescript type definitions for
workbox-swand provides them from thetypesproperty of the package.json of that package.The type declarations are complete and based on the reference docs.
Also, during linting, ESLint complained about a few invalid JSDoc comments in some other files, so I've also fixed those.