• Get a TypeScript type for the (picked) configuration object

    Type Parameters

    Parameters

    • config: T

      the configuration definition object to get the Type for

    Returns ValueObject<T>

    Example

    import { from } from 'env-var';

    export const getConfigDefinitions = (
    variables: NodeJS.ProcessEnv = process.env,
    ) => {
    const env = from(variables);

    return {
    environment: () => env.get('NODE_ENV').required().asEnum(['development', 'production', 'test']),
    serviceId: () => env.get('SERVICE_ID').required().asString(),
    port: () => env.get('PORT').default(10100).asPortNumber(),
    // many more...
    }
    }

    // validation will not happen at that point in time
    const config = getConfigType(getConfigDefinitions());
    export type Config = typeof config;

Generated using TypeDoc