-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using official Cloudflare types #156
Comments
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 worktop can't and won't use the CF types package because:
|
I understand that one goal for 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:
I don't think either solution is what you want developers to do, and since Cloudflare recommends new projects to use |
What request.cf property is outdated? Let’s just fix that. It changes infrequently. |
Cool, I'll do a PR |
Currently,
worktop
hardcodes TypeScript types forrequest.cf
at https://github.com/lukeed/worktop/blob/next/packages/worktop/src/cfw.d.ts. Over time, these static types drift from the actual implementation. For example, we're missing fields likeclientTcpRtt
andasOrganization
. Cloudflare now publishes@cloudflare/workers-types
, which has automatically generated TS types based on their current APIs, and they tend to be relatively up-to-date. Perhapsworktop
could add@cloudflare/workers-types
as a peer dependency, remove hardcoded types fromsrc/cfw.d.ts
, and use the link/// <reference types="@cloudflare/workers-types" />
when you need to refer to the official CF types?The text was updated successfully, but these errors were encountered: