Skip to content
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

🚀 Feature Request: wrangler types generates wider types for environment variables #5082

Open
mw10013 opened this issue Feb 23, 2024 · 4 comments · May be fixed by #5086
Open

🚀 Feature Request: wrangler types generates wider types for environment variables #5082

mw10013 opened this issue Feb 23, 2024 · 4 comments · May be fixed by #5086
Labels
enhancement New feature or request

Comments

@mw10013
Copy link

mw10013 commented Feb 23, 2024

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'.

Screenshot 2024-02-23 at 3 22 04 PM
@dario-piotrowicz
Copy link
Member

dario-piotrowicz commented Feb 24, 2024

@mw10013 thanks for the issue 🙂

I've opened a PR to hopefully address this: #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

@mw10013
Copy link
Author

mw10013 commented Feb 25, 2024

@dario-piotrowicz : I tried the PR prerelease and it works perfectly for my use case. World class typing. Thanks!

@dario-piotrowicz
Copy link
Member

@mw10013 great! 🚀 thanks for giving it a try! 😄

@peter-stewart-thg
Copy link

Did this ever get resolved?
Seemingly still an issue and makes the type generation unusable for environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants