-
Notifications
You must be signed in to change notification settings - Fork 89
-
Notifications
You must be signed in to change notification settings - Fork 89
RFC: Exportable types #295
Comments
Does Frankenstein's approach work for the other types as well? Any reason not to do that and be consistent on everything? |
Additionally, can we keep the global types for those that want to continue using workers-types in the v2 way? |
|
If we publish an ambient |
Hey @jacob-ebey, we're thinking about publishing importable Workers runtime types, as well as continuing to offer the global types. Do you have any thoughts on this? Would there be interest in using the importable types in the Remix packages/templates? Or does it make sense only for users to use directly themselves? |
We should be able to close all these issues if we do this: |
I'm going to close this, as you can now |
One request we've had is to provide user importable types from this package—i.e. a way to use worker types without declaring it in
tsconfig.json
. This is easy enough for most of our types (ExecutionContext
, for instance):The rest of this issues will address options for providing importable types for globals like
Response
,Request
, andfetch
, which are both values and types.Is this a problem to solve?
The workers runtime does have the globals
Response
etc..., and so in some sense using ambient declarations is the "right" approach (as this package does currently). However, there are downsides, including the lack of automatic inclusion of@types/*
packages, and the fact that workers can't be typed correctly in frameworks like Remix, which mix browser code and worker code in the same project (and even file!).Here's a very simple example of a Remix file that doesn't typecheck, because
Response.json()
is non standard. It runs fine when published, asResponse.json()
is available in the workers runtime.How about just...exporting the types?
At first glance, just adding an
export
keyword would seem to solve the issue:Indeed, this typechecks fine, but doesn't build fine (
esbuild
can't find theResponse
export).An honestly pretty reasonable option for classes
This both typechecks and builds with
esbuild
, as well as (as far as I can tell) working completely fine in the runtime.It also provides a solution for the Remix example given earlier:
Frankenstein's monster
One type remains; the function:
I propose the following solution:
This typechecks, builds, and runs correctly, but is a bit...horrifying. If anyone has any suggestions on how to improve this I'm all ears!
The text was updated successfully, but these errors were encountered: