question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FetchEvent constructor no longer accepts second argument

See original GitHub issue

Problem

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:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lookfirstcommented, Dec 4, 2021

It was complaining at first, but clearing the cache and restarting the project cleared that up. We have success! Thanks for your patience.

2021-12-04 12-21-33

1reaction
vlovichcommented, Oct 29, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found