fix: use DotenvPopulateOptions for populate() third argument type#998
Merged
Merged
Conversation
The populate() function only reads `debug` and `override` from its options argument, but was typed to accept the broader DotenvConfigOptions interface. This gave TypeScript users misleading autocomplete suggesting that options like `path`, `encoding`, `quiet`, and `DOTENV_KEY` are valid for populate() when they are not. - Change populate() options parameter from DotenvConfigOptions to DotenvPopulateOptions - Fix JSDoc example on populate() that incorrectly listed `quiet` as a valid option - Fix JSDoc examples inside DotenvPopulateOptions to reference populate() instead of config() - Add populate() type usage to tests/types/test.ts to cover this in the dts-check
Owner
|
thank you for a helpful contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
populate()function accepts three arguments:processEnv,parsed, andoptions. Its implementation only readsdebugandoverridefromoptions— exactly the two fields defined inDotenvPopulateOptions.However, the type signature in
lib/main.d.tstyped the third argument asDotenvConfigOptions, which is the broader interface that also includespath,encoding,quiet,processEnv, andDOTENV_KEY. None of those extra fields do anything insidepopulate().This meant TypeScript users got misleading IntelliSense: autocomplete would suggest
quiet,path,encoding, etc. as valid options forpopulate(), when they are silently ignored at runtime.There was also a secondary issue: the JSDoc
@param optionsexample onpopulate()showed{ quiet: false, debug: true, override: false }, referencingquietwhich is not part ofDotenvPopulateOptionsand does nothing inpopulate().Changes
lib/main.d.ts: Changepopulate()third argument fromDotenvConfigOptionstoDotenvPopulateOptionslib/main.d.ts: Fix@param optionsJSDoc example to removequietand only showdebug/overridelib/main.d.ts: Fix the JSDoc examples insideDotenvPopulateOptionsfields to referencepopulate()instead ofconfig()tests/types/test.ts: Addpopulate()usage to the TypeScript type test so thedts-checkscript covers this function going forwardVerification
The
DotenvPopulateOptionsinterface already existed in the type file — it just wasn't being used forpopulate(). This change connects the two correctly.