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 proposal] Use .d.ts as schema for type safety #38

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

lhhong
Copy link

@lhhong lhhong commented May 8, 2020

This proposal adds type safety for typescript by providing the ability to use type declarations directly as a schema. With schema checking, we can take advantage of the fact that this library ensures the respective keys in process.env will be present.

Existing solutions are not as great. We could litter the typescript code with if KEY !== undefined or with !! operator but risk having typographical errors. Having process.env type declaration facilitates code completion. While we can use a type declaration separate from the schema, being able to have one single source of truth avoids the need to change multiple places.

Notes

  1. README not updated
  2. Union string types not supported, future additions could include that with checking
  3. I have also considered declaration code generation but it can be painful for a small project without proper build pipelines

Breaks: type declaration of IEnvironmentMap changed to { [name: string]: string | undefined }. I believe dotenv's type declaration of { [name: string]: string } is a mistake. With this change, it no longer makes sense to carry this mistake down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant