Skip to content

Support loading config files written in TypeScript #16

Description

@hirotask

Summary

Add support for loading configuration files written in TypeScript.

Motivation

Many modern projects use TypeScript as their primary language. Requiring users to write configuration files in JavaScript introduces friction and breaks consistency within TypeScript-based codebases. Supporting TypeScript config files improves developer experience and aligns with common ecosystem practices.

Definition of done

  • Configuration files written in TypeScript (e.g., .ts) can be loaded correctly.
  • Both ESM and CommonJS TypeScript configs are supported where applicable.
  • Existing JavaScript-based config loading continues to work without breaking changes.
  • The behavior and requirements (e.g., runtime dependencies) are clearly described in a PR.
  • Tests are added to verify TypeScript config loading.

Proposed approach

  • Introduce a mechanism to load TypeScript config files at runtime.
  • Use tools such as ts-node, tsx, or a lightweight transpilation step (e.g., esbuild-register) to execute .ts files.
  • Detect config file extensions (e.g., .ts, .mts, .cts) and apply the appropriate loader.
  • Normalize the exported config (e.g., handle default export consistently).
  • Ensure compatibility with both ESM and CommonJS environments.
  • Document any required peer dependencies or setup steps for users.

Additional context

Example of a TypeScript config file:

import type { Config } from 'flagly';

const config: Config = {
  flagSource: (key, defaultValue) => defaultValue,
  baseEnv: {},
};

export default config;

Consider whether to:

  • Require users to install a runtime (e.g., tsx)
  • Or provide a built-in lightweight loader

This decision impacts usability, performance, and maintenance.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions