cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.75k stars 733 forks source link

`FetchEvent` is not assignable to parameter of type `Evt` #4971

Closed whoabuddy closed 5 months ago

whoabuddy commented 2 years ago

We have a simple API setup from the TS worker template with itty-router, and up until now it's been working great.

I went to update some packages/dependencies today, and am now unable to complete a build due a type error with getAssetFromKV:

Argument of type 'FetchEvent' is not assignable to parameter of type 'Evt'.
  Property 'waitUntil' is missing in type 'FetchEvent' but required in type 'Evt'.ts(2345)
index.d.ts(32, 5): 'waitUntil' is declared here.

The documentation in this repository shows the exact same format we're using for handling the event.

https://github.com/citycoins/api/blob/fed3fa78d583e290a09306631c82664eca61e339/src/index.ts#L4-L12

If the URL matches an allowed file extension in the root path, then it tries to return that file instead of sending requests to the router. One example from the working deployment before changes is openapi.yml used to generate the documentation page.

https://github.com/citycoins/api/blob/fed3fa78d583e290a09306631c82664eca61e339/src/index.ts#L29-L43

Since addEventListener produces a FetchEvent by default, what is the best approach to pass the correct values to getAssetFromKV? I saw an approach in cloudflare/workers-sdk#4973 that may work, but couldn't find a spot in the docs that made me confident this was the best way to move forward.


Adding to this I reverted the commit locally and tested to be sure - can confirm it compiles with no errors and works as expected.

The packages that were updated as part of the breaking change were:

 itty-router                        ^2.4.10  →   ^2.6.1
 micro-stacks                        ^0.2.2  →   ^0.3.0
 @cloudflare/workers-types           ^3.0.0  →   ^3.9.0
 @types/jest                       ^26.0.23  →  ^27.5.0
 @typescript-eslint/eslint-plugin   ^4.16.1  →  ^5.23.0
 @typescript-eslint/parser          ^4.16.1  →  ^5.23.0
 eslint                             ^7.21.0  →  ^8.15.0
 eslint-config-prettier              ^8.1.0  →   ^8.5.0
 jest                               ^27.0.1  →  ^28.1.0
 prettier                            ^2.3.0  →   ^2.6.2
 ts-jest                            ^27.0.1  →  ^28.0.2
 ts-loader                           ^9.2.2  →   ^9.3.0
 typescript                          ^4.3.2  →   ^4.6.4
 webpack                            ^5.38.1  →  ^5.72.0
 webpack-cli                         ^4.7.0  →   ^4.9.2
penalosa commented 5 months ago

I’m going to close this issue for now. Going forward, we’ll revisit the assets system as part of Pages/Workers convergence, and will inherit the benefits of the Pages assets system.

In the meantime, Pages is the best choice for deploying sites with static assets. If you're still running into problems feel free to comment with a reproduction and we can investigate further.