Class: ConfigPowers
Methods
get()
Call Signature
static get<TConfig, TReturn>(key): Promise<TReturn>;
Retrieves a configuration value from the ConfigService.
This method has three signatures:
-
When a specific configuration type is known (i.e., extends ConfigProperties), and the expected property type is known, you can provide the type as TConfig and the return type as TReturn, which is the type of the property specified by key.
-
When the specific configuration object type is known but the property type is not specified, the method will return a Promise with the type inferred from the configuration type.
-
When the type is not known, you can call the method with a string key, and it will return a Promise with an unknown type.
Type Parameters
| Type Parameter | Description |
|---|---|
TConfig extends ConfigProperties |
The expected configuration object type that extends ConfigProperties. |
TReturn |
The expected return type of the configuration object property. |
Parameters
| Parameter | Type | Description |
|---|---|---|
key |
keyof TConfig |
The key corresponding to the configuration value to retrieve. |
Returns
Promise<TReturn>
A promise that resolves to the configuration value associated with the given key.
Examples
// Use with a known config type and known property type
type ExampleConfig = {host: string; url: string};
const host = await ConfigPowers.get<ExampleConfig, string>('host');
console.log(host); // Outputs the host value from the configuration
// Use with a known config type but unknown property type
type ExampleConfig = {host: string; url: string};
const configValue = await ConfigPowers.get<ExampleConfig>('host');
console.log(configValue); // Outputs the value from the configuration, type inferred from ExampleConfig
// Use with an unknown config type
const value = await ConfigPowers.get('someKey');
console.log(value); // Outputs the value from the configuration of unknown type
Call Signature
static get<TConfig>(key): Promise<TConfig[keyof TConfig]>;
Retrieves a configuration value from the ConfigService.
This method has three signatures:
-
When a specific configuration type is known (i.e., extends ConfigProperties), and the expected property type is known, you can provide the type as TConfig and the return type as TReturn, which is the type of the property specified by key.
-
When the specific configuration object type is known but the property type is not specified, the method will return a Promise with the type inferred from the configuration type.
-
When the type is not known, you can call the method with a string key, and it will return a Promise with an unknown type.
Type Parameters
| Type Parameter | Description |
|---|---|
TConfig extends ConfigProperties |
The expected configuration object type that extends ConfigProperties. |
Parameters
| Parameter | Type | Description |
|---|---|---|
key |
keyof TConfig |
The key corresponding to the configuration value to retrieve. |
Returns
Promise<TConfig[keyof TConfig]>
A promise that resolves to the configuration value associated with the given key.
Examples
// Use with a known config type and known property type
type ExampleConfig = {host: string; url: string};
const host = await ConfigPowers.get<ExampleConfig, string>('host');
console.log(host); // Outputs the host value from the configuration
// Use with a known config type but unknown property type
type ExampleConfig = {host: string; url: string};
const configValue = await ConfigPowers.get<ExampleConfig>('host');
console.log(configValue); // Outputs the value from the configuration, type inferred from ExampleConfig
// Use with an unknown config type
const value = await ConfigPowers.get('someKey');
console.log(value); // Outputs the value from the configuration of unknown type