Learn how to gradually adopt Typeconf in your existing TypeScript project
Typeconf is designed to be adopted gradually in your existing TypeScript
projects. This guide will show you how to introduce Typeconf step by step
without having to rewrite your entire codebase or change your habits too much.
$ npm install --save @typeconf/sdk# Or with React/Next$ npm install --save @typeconf/react-sdk
Use the configuration in your app:
Copy
import { UserSettings } from "./configs/types";import { readConfig } from "@typeconf/sdk";// with React: import { readConfig } from "@typeconf/react-sdk/server";function UserPreferences() { // Path to your config without extension const config: UserSettings = readConfig("configs/user-settings"); // Your config is now fully typed and validated console.log(config.theme); // 'light'}
Start with New Features: When adding new features, use Typeconf from the
start rather than converting existing code.
Identify High-Value Targets: Focus on areas where type-safe configuration would provide the most value:
Complex configuration objects
Frequently changing settings
Areas prone to configuration errors
Maintain Backward Compatibility: When converting existing configurations:
Copy
// Wrap existing config with Typeconf type while maintaining// the old interfaceconst legacyConfig = { // ... your existing config} as TypeconfConfig;const newConfig: TypeconfConfig = readConfig(...);// Provide both until migration is completeexport const config = { ...legacyConfig, ...newConfig};