Docs

Evaluating Flags

Get flag values with type-safe methods

Last updated:

Boolean Flags

typescript
const showNewCheckout = FeatureFlags.getBooleanFlag('new-checkout', false);

if (showNewCheckout) {
  // Render new checkout flow
} else {
  // Render existing checkout
}

The second argument is the default value, returned when:

  • The flag doesn’t exist
  • The client hasn’t been initialized
  • The flag is disabled in this environment

String Flags

typescript
const buttonColor = FeatureFlags.getStringFlag('cta-color', 'blue');

Refreshing Flags

Flags are fetched once on init(). To re-evaluate with new context (e.g., after a user upgrades their plan):

typescript
await FeatureFlags.refresh({
  userId: 'user-123',
  plan: 'pro', // updated context
});

// Flags are now re-evaluated with the new context
const hasAdvancedFeatures = FeatureFlags.getBooleanFlag('advanced-features', false);

Listing All Flags

Retrieve all flag definitions for your property:

typescript
const result = await FeatureFlags.getFlags();

for (const flag of result.flags) {
  console.log(flag.key, flag.type, flag.defaultValue);
}

Each flag in the result includes id, key, name, type, defaultValue, and createdAt. This is useful for building admin UIs or syncing flag state.

Checking Initialization

typescript
if (FeatureFlags.isInitialized()) { /* Safe to read flags */ }

API Reference

MethodReturnsDescription
init(config, context?)Promise<void>Initialize and fetch flags
getBooleanFlag(key, default)booleanGet a boolean flag value
getStringFlag(key, default)stringGet a string flag value
refresh(context?)Promise<void>Re-evaluate with new context
getFlags()Promise<FlagListResult>List all flag definitions for the property
isInitialized()booleanWhether init() has completed
destroy()voidCleanup