workers-sdk
workers-sdk copied to clipboard
🚀 Feature Request: `wrangler types` generates wider types for environment variables
Describe the solution
wrangler types seems to generate literals for environment variables in wrangler.toml. A wider type like string may be more helpful.
[vars]
ENVIRONMENT = "development"
generates
interface Env {
ENVIRONMENT: "development";
}
Typescript then complains when I try to compare ENVIRONMENT against, say, 'production'.
@mw10013 thanks for the issue 🙂
I've opened a PR to hopefully address this: https://github.com/cloudflare/workers-sdk/pull/5086
With my changes if you have your variable defined in multiple environments in your config file and run wrangler types instead of getting the single string literal you get a union of all the possible values, please have a look and let me know if it does solve the issue 🙂🙏
PS: you can try seeing if the PR's prerelease works for you by running:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8032131415/npm-package-wrangler-5086 types
@dario-piotrowicz : I tried the PR prerelease and it works perfectly for my use case. World class typing. Thanks!
@mw10013 great! :rocket: thanks for giving it a try! :smile: