ConfigService

  
class ConfigService<K = Record<string, unknown>, WasValidated extends boolean = false> {
  get<T = any>(propertyPath: KeyOf<K>, defaultValueOrOptions?: ConfigGetOptions | T, options?: ConfigGetOptions): T | undefined
  getOrThrow<T = any>(propertyPath: KeyOf<K>, defaultValueOrOptions?: ConfigGetOptions | T, options?: ConfigGetOptions): Exclude<T, undefined>
}

Methods

get()

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist.

Overload #1

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").


get<T = any>(propertyPath: KeyOf<K>): ExcludeUndefinedIf<WasValidated, T>

Parameters

Option Type Description
propertyPath KeyOf

Returns

ExcludeUndefinedIf<WasValidated, T>


Overload #2

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").


get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, options: ConfigGetOptions): ExcludeUndefinedIf<WasValidated, R>

Parameters

Option Type Description
propertyPath P
options ConfigGetOptions

Returns

ExcludeUndefinedIf<WasValidated, R>


Overload #3

get<T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): T

Parameters

Option Type Description
propertyPath KeyOf
defaultValue NoInferType

Returns

T


Overload #4

get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): R

Parameters

Option Type Description
propertyPath P
defaultValue NoInferType
options ConfigGetOptions

Returns

R

getOrThrow()

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist. If the default value is undefined an exception will be thrown.

Overload #1

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").


getOrThrow<T = any>(propertyPath: KeyOf<K>): Exclude<T, undefined>

Parameters

Option Type Description
propertyPath KeyOf

Returns

Exclude<T, undefined>


Overload #2

Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").


getOrThrow<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, options: ConfigGetOptions): Exclude<R, undefined>

Parameters

Option Type Description
propertyPath P
options ConfigGetOptions

Returns

Exclude<R, undefined>


Overload #3

getOrThrow<T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): Exclude<T, undefined>

Parameters

Option Type Description
propertyPath KeyOf
defaultValue NoInferType

Returns

Exclude<T, undefined>


Overload #4

getOrThrow<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): Exclude<R, undefined>

Parameters

Option Type Description
propertyPath P
defaultValue NoInferType
options ConfigGetOptions

Returns

Exclude<R, undefined>