cloudflare / workerd

The JavaScript / Wasm runtime that powers Cloudflare Workers
https://blog.cloudflare.com/workerd-open-source-workers-runtime/
Apache License 2.0
6.05k stars 287 forks source link

Feature 🚀 : Add a new `Env` type that can be used and extended externally #1899

Open dario-piotrowicz opened 5 months ago

dario-piotrowicz commented 5 months ago

Adding a new Env type in the workers-types package could be beneficial as it could be used/leveraged by users and library/framework authors.

I made this simple POC regarding this: https://github.com/dario-piotrowicz/workers-types-env-poc

(in the POC's workers-types's node_modules directory you can see the type of change I have in mind, only applied to the experimental entrypoint there)


This could be beneficial for uses of getPlatformProxy such as nitro-cloudflare-dev (see https://github.com/pi0/nitro-cloudflare-dev/pull/13) (cc. @pi0, @Aslemammad)


We've been also asked about this from the Remix team once. Their reasoning there being that having an Env interface somewhere, always guaranteed to exist, allows for libraries to be written with more stable/robust typing instead of having to reply on a global Env interface that might or not exist, @pcattori please feel free to add context here regarding this if you want 🙂.


This needs a bit of discussion though as the introduction of such a type, although not complex would likely not be trivial and the effort of implementing and maintaining such type could outweigh the benefits 🤔

Aslemammad commented 5 months ago

This would be huge for one of my projects! It adds much more flexibility and type-safety. Thank you so much y'all for tracking this.