FetchEvent constructor no longer accepts second argument
See original GitHub issueProblem
According to the FetchEvent spec the FetchEvent
constructor accepts an optional second argument called init
. I think this worked in 2.2.1
but stopped working in 3.0.0
.
Motivation:
I’m using the init.request
argument in my tests like so
new FetchEvent("fetch", {
request: new CfRequest("/foo", { method: "GET" }),
})
to test the handler passed to addEventListener("fetch", (event) => {})
with a fake event
. This creation of the fetchEvent
now being marked as invalid by TypeScript.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Cannot construct a Request with a Request whose mode is ...
At the same time, I want them to be fetched just as the sender intended; meaning I want to set second argument of...
Read more >Request · Cloudflare Workers docs
The most common way you will encounter a Request object is as a property of an incoming FetchEvent . addEventListener("fetch", event ...
Read more >Declarative routing · Issue #1373 · w3c/ServiceWorker - GitHub
These interfaces don't currently have attributes, but they could have attributes that reflect the options/defaults passed into the constructor.
Read more >What is the second argument that can optionally be passed to ...
The second argument that can optionally be passed to setState is a callback function which gets called immediately after the setState is ...
Read more >Using the Fetch API - MDN Web Docs
The fetch() method can optionally accept a second parameter, an init object that allows you to control a number of different settings:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It was complaining at first, but clearing the cache and restarting the project cleared that up. We have success! Thanks for your patience.
I think this is a compliance issue in the runtime itself & not an issue with the types. We actually don’t support constructing a FetchEvent & the exposition of the constructor at all is an oversight in the typing. The next release will remove the FetchEvent constructor until it’s actually available in the Runtime.