Skip to main content

The Type Safety Problem

Traditional feature flag systems use string literals and untyped values:

FlagKit’s Type-Safe Approach

FlagKit generates TypeScript types from your flag definitions:

Generated Types

Running flagkit generate creates comprehensive TypeScript types:

Type-Checked API

The flags.get() method is fully type-checked:

Compile-Time Validation

FlagKit catches errors at compile time, not runtime:

1. Typos in Flag Names

2. Invalid Default Values

flags.config.ts

3. Type Mismatches

Refactoring Safety

Rename flags confidently using TypeScript’s refactoring tools:
Use your IDE’s “Find All References” feature to locate all usages of a flag before renaming.

Type-Safe Context

Context values are also type-checked:

Enum Flags

Enum flags get full type safety:
flags.config.ts

Number Flags with Constraints

Number flags can have min/max constraints:
flags.config.ts
TypeScript can enforce type (string, number, boolean) but not value ranges. Runtime validation ensures values stay within constraints.

Pattern-Based String Flags

String flags can use regex patterns for validation:
flags.config.ts

Benefits Summary

Catch Errors Early

Compile-time validation prevents runtime failures

IDE Support

Autocomplete, go-to-definition, and refactoring tools

Self-Documenting

Types serve as inline documentation

Refactor Safely

Rename flags without breaking code

Next Steps

Deterministic Rollouts

Learn about type-safe percentage-based rollouts