Problems: Nestjs config service with optional environment variables
ConfigService.get
is string undefined
Return value from When the validate function returns an object where a key, e.g. OPT
, is undefined
, assignVariablesToProcess
will assign undefined
to process.env.OPT
which will stringify it (see https://nodejs.org/api/process.html#processenv). This results in ConfigService.get
returning process.env.OPT
which now has the value 'undefined'
.
Reproduce
yarn run start
and observe the log.
ConfigService<EnvironmentVariables, true>.get
excludes undefined
Return type from The second generic parameter (WasValidated
) changes the return value of ConfigService.get
. If true
, it removes undefined
from the return type. If false
, it adds undefined
. The problem here is that a value could be both validated and undefined
.
Reproduce
Observe the TypeScript return type of optValue
in main.ts
.