This article presents some improvements introduced in version 2 of FoalTS:
.env
files (.env
, .env.test
, etc)Starting from version 2, great attention is paid to type safety in the configuration. The
Config.get
method allows you to specify which type you expec
const timeout = Config.get('custom.timeout', 'number');
// The TypeScript type returned by `get` is number|undefined.
In this example, when calling the
get
method, the framework will look at the configuration files to retrieve the desired value.
undefined
."1"
), the function converts and returns it.ConfigTypeError
with the details. Note that the config value is not logged to avoid leaking sensitive information.If you wish to make the config parameter mandatory, you can do it by using the getOrThrow
method. If no value is found, then a ConfigNotFound
error is thrown.
#typescript #javascript #js #nodejs #node