Comments (10)
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.
from workers-types.
It was complaining at first, but clearing the cache and restarting the project cleared that up. We have success! Thanks for your patience.
from workers-types.
I'll close this as I understand that FetchEvent
was not exposed on purpose and this issue is thus irrelevant. Thanks for clarifying!
As a wacky solution for my specific issue, I found that using /// <reference lib="webworker" />
in my test files solves it for now. There's probably a much cleaner solution, but who's got the time eh
from workers-types.
@vlovich You might not support constructing a FetchEvent, but it is still necessary.
addEventListener('fetch', (event: any) => {
event.respondWith(router.handle(event.request));
});
That is ugly.
from workers-types.
Hey! 👋 FetchEvent
is still included in the typings (just without the constructor), so you can still do:
addEventListener('fetch', (event: FetchEvent) => {
event.respondWith(router.handle(event.request));
});
Additionally, when using the global addEventListener
, the type of event
is inferred for fetch
and scheduled
events, so you can actually omit FetchEvent
:
addEventListener('fetch', (event) => {
// event is automatically typed FetchEvent
event.respondWith(router.handle(event.request));
});
from workers-types.
@mrbbot I see it in there, but it doesn't show up in IDEA for some reason... thoughts?
"@cloudflare/workers-types": "^3.2.0",
from workers-types.
Also:
from workers-types.
@lookfirst You have dom
in the compilerOptions.lib
array. @cloudflare/workers-types
conflicts with this so you'll need to remove dom
from that list.
If you've also got a front-end web app in the same project, you may want to add a separate tsconfig.json
that extends this root one in the front-end's directory:
// e.g. web/tsconfig.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": ["esnext", "dom"],
"types": []
}
}
from workers-types.
@mrbbot Thanks. I was getting errors without "dom" in there before, but it seems like that is magically gone now. That said, FE still isn't showing up... it is part of miniflare?
I do not have a web project at all, it is just a worker.
from workers-types.
FetchEvent
is included in miniflare
, but it's also included in workers-types
so you shouldn't need to import it. If you just write FetchEvent
there (without importing anything), does IDEA complain? Have you tried restarting the TypeScript language service?
from workers-types.
Related Issues (20)
- Missing properties on IncomingRequestCfPropertiesBotManagement HOT 1
- Incorrect D1 types HOT 2
- RequestInit is missing some properties like 'cache' HOT 3
- Generate types from `workerd` RTTI HOT 1
- RFC: Exportable types HOT 7
- Fix `request.cf` types
- Generate exportable version of `workers-types` HOT 1
- add JSDocs documentation in types
- Move overrides to `workerd` C++ source code HOT 1
- Include C++ parameter names in types generated from JSG RTTI HOT 2
- Get type hints on incoming Request object HOT 4
- IncomingRequestCfPropertiesGeographicInformation makes geo property access an error (regression from 3.17.0) HOT 7
- HtmlRewriter ElementHandler methods can only accept strings (not general Content) HOT 1
- (3.18.0) IncomingRequestCfPropertiesGeographicInformation is the wrong type HOT 2
- Class 'Request<ParamKeyType, Data>' incorrectly extends base class 'Body' HOT 1
- `new Request` bad type HOT 8
- addEventListener has a broken type definition HOT 1
- NPM Release @cloudflare/worker-types 4.20221111.0 HOT 2
- Add Symbol.iterator to WebScoketPair HOT 1
- What is Fetcher for? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workers-types.