config-file-ts is a JavaScript/TypeScript library that enables developers to utilize TypeScript directly for application configuration files, moving beyond the limitations of JSON or YAML. It introduces greater flexibility by supporting comments, unquoted object keys, and trailing array commas, while also allowing for programmatic logic within configs—such as variable sharing or the use of utility functions. A significant advantage is the integration with TypeScript's type system, which provides compile-time error checking and enhanced IDE support for ensuring configuration correctness. The library includes a caching mechanism for compiled TypeScript output to maintain fast parsing performance with minimal runtime overhead. The latest stable version appears to be 0.1.4, with a 0.2.8-rc1 pre-release available. Release cadence is not explicitly defined but appears infrequent based on the provided history.
npm install config-file-tsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a TypeScript configuration file (`my.config.ts`) with a default export, leverage Node.js modules like 'os' within it, and then load and type-check this configuration in a main application file (`MyProgram.ts`) using `loadTsConfig`.
Ensure `typescript` is installed as a dependency or peer dependency in your project: `npm install typescript` or `yarn add typescript`.
Refactor your configuration file to ensure the primary configuration object is exported as `export default { ... }`.Keep configuration files relatively simple. Ensure your `tsconfig.json` (if used for the config file) is optimized, or consider pre-compiling if startup time is critical and the config rarely changes.
Install `typescript` as a dependency: `npm install typescript` or `yarn add typescript`.
Ensure your `.ts` config file exports its main configuration object using `export default { /* config */ };`.Review your configuration file and the `MyConfig` interface (or similar type). Adjust either the configuration object's structure/values or the type definition to ensure they are compatible. Use `as MyConfig` in the config file to enforce the type check.