Comments (4)
worktop is meant to be completely self-sufficient. You can/should use it directly and have information be accurate and up to date. In fact, until @cloudflare/workers-types
2.0 release, the worktop types for CF Workers were more accurate than the 1.x types.
worktop can't and won't use the CF types package because:
- worktop isn't exclusively a CF framework
- the CF types are globals and are meant only for a Cloudflare Workers environment
This means that the type information included would be inaccurate for Deno, for example, and global types are all-or-nothing. - the CF types are not 1:1 with the shared global names
The types reflect the CF runtime, which is great, but if there are any spec compliance issues, they'll collide with TS internals and report as errors. - Because of (3) you can't actually use
@cloudflare/workers-types
alongside the"dom"
or"webworker"
built-in types.
from worktop.
I understand that one goal for worktop
is to be runtime-agnostic. However, the project currently defines types for request.cf
this way:
worktop/packages/worktop/src/cfw.d.ts
Lines 23 to 25 in 42b8dc5
This
cf
field is specific to Cloudflare, and if developers access req.cf
they expect this property to reflect the behavior of Cloudflare Workers (what fields exist, what is nullable/optional, etc). The issue is that IncomingCloudflareProperties
is hardcoded, and has become outdated. It seems that worktop
cannot choose not to ship this type for Cloudflare Workers, it can only choose between "duplicate, and maintain regularly" or "reference the official definitions maintained by Cloudflare".
I found two ways around this issue:
- Cast the
cf
property manually in every handler, e.g.const cf = req.cf as unknown as IncomingRequestCfProperties
; - Override the type within
worktop
, e.g. inglobal.d.ts
:
/// <reference types="@cloudflare/workers-types" />
declare module "worktop/cfw" {
interface IncomingCloudflareProperties extends IncomingRequestCfProperties {}
}
I don't think either solution is what you want developers to do, and since Cloudflare recommends new projects to use @cloudflare/workers-types
, these conflicts will become more common. Embracing @cloudflare/workers-types
should reduce your long-term burden for worktop
as Cloudflare now actively maintains that package.
from worktop.
What request.cf property is outdated? Let’s just fix that. It changes infrequently.
from worktop.
Cool, I'll do a PR
from worktop.
Related Issues (20)
- Use Sveltekit and worktop together? HOT 2
- How to set multiple cookies? HOT 2
- Worktop Middlewares Example HOT 4
- Durable Objects example HOT 2
- The example of timing requests might be misleading HOT 1
- Can I use Worktop with Fastly Compute@Edge? HOT 1
- Is it going to be official by cloudflare?
- Cache API and KV: Concerns/Questions/Usage HOT 1
- How to access `.env` with Wrangler 2 HOT 2
- Provide a "test" module HOT 4
- Serving HTML files HOT 6
- How to use with cron / scheduled event ? HOT 2
- Is `worktop@next` safe to use in production? HOT 2
- Add generic typing for Router.add handler
- The uploaded script has no registered event handlers. [API code: 10068] HOT 1
- Add sub-routers HOT 2
- Node 16+ ESM TypeScript error HOT 1
- `isCacheable` allowed cache by default if the `cache-control` header is empty may leading to a security flaw in ssg content HOT 2
- Router doesn't route when using service bindings HOT 7
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 worktop.