Skip to content

fix: use DotenvPopulateOptions for populate() third argument type#998

Merged
motdotla merged 1 commit into
motdotla:masterfrom
mahmoodhamdi:fix/populate-options-type
Apr 1, 2026
Merged

fix: use DotenvPopulateOptions for populate() third argument type#998
motdotla merged 1 commit into
motdotla:masterfrom
mahmoodhamdi:fix/populate-options-type

Conversation

@mahmoodhamdi
Copy link
Copy Markdown
Contributor

Problem

The populate() function accepts three arguments: processEnv, parsed, and options. Its implementation only reads debug and override from options — exactly the two fields defined in DotenvPopulateOptions.

However, the type signature in lib/main.d.ts typed the third argument as DotenvConfigOptions, which is the broader interface that also includes path, encoding, quiet, processEnv, and DOTENV_KEY. None of those extra fields do anything inside populate().

This meant TypeScript users got misleading IntelliSense: autocomplete would suggest quiet, path, encoding, etc. as valid options for populate(), when they are silently ignored at runtime.

There was also a secondary issue: the JSDoc @param options example on populate() showed { quiet: false, debug: true, override: false }, referencing quiet which is not part of DotenvPopulateOptions and does nothing in populate().

Changes

  • lib/main.d.ts: Change populate() third argument from DotenvConfigOptions to DotenvPopulateOptions
  • lib/main.d.ts: Fix @param options JSDoc example to remove quiet and only show debug/override
  • lib/main.d.ts: Fix the JSDoc examples inside DotenvPopulateOptions fields to reference populate() instead of config()
  • tests/types/test.ts: Add populate() usage to the TypeScript type test so the dts-check script covers this function going forward

Verification

npm test  # all 194 tests pass, lint clean, dts-check passes

The DotenvPopulateOptions interface already existed in the type file — it just wasn't being used for populate(). This change connects the two correctly.

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
@motdotla
Copy link
Copy Markdown
Owner

motdotla commented Apr 1, 2026

thank you for a helpful contribution.

@motdotla motdotla merged commit 093b8c2 into motdotla:master Apr 1, 2026
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.

2 participants