Flagdeck supports multiple value types for feature flags, giving you flexibility beyond simple on/off toggles. This page explains the different value types available and how to work with them in your application.
Flagdeck supports the following value types:
Boolean flags are the most common type, used to toggle features on or off.
In the Flagdeck dashboard, create a boolean flag by selecting "Boolean" as the value type.
// Check if a feature is enabled
const isEnabled = await flagdeck.isEnabled('new-feature');
if (isEnabled) {
// Show the new feature
showNewFeature();
} else {
// Show the existing experience
showExistingExperience();
}
You can also use getValue
with explicit typing:
const isEnabled = await flagdeck.getValue<boolean>('new-feature', context, false);
String variants are useful for A/B testing or feature modes.
In the Flagdeck dashboard, create a string flag by selecting "String" as the value type and defining your variants.
// Get the variant with a default fallback value
const variant = await flagdeck.getValue('button-color', context, 'blue');
switch (variant) {
case 'red':
renderRedButton();
break;
case 'green':
renderGreenButton();
break;
default: // 'blue' or any fallback
renderBlueButton();
break;
}
This is particularly useful for experimentation:
const experiment = await flagdeck.getValue('pricing-experiment', context, 'control');
if (experiment === 'variant-a') {
showPricingA();
} else if (experiment === 'variant-b') {
showPricingB();
} else {
showDefaultPricing(); // control
}
Numeric flags allow you to remotely configure thresholds, limits, or other numeric values.
In the Flagdeck dashboard, create a number flag by selecting "Number" as the value type.
// Get a numeric limit with default value
const itemLimit = await flagdeck.getValue('item-limit', context, 10);
// Use the number in your application logic
if (itemCount > itemLimit) {
showLimitReachedMessage();
}
You can use numeric flags for various purposes:
// Request timeout setting
const timeout = await flagdeck.getValue('api-timeout', context, 5000);
makeAPIRequest({ timeout });
// Feature score threshold
const threshold = await flagdeck.getValue('recommendation-threshold', context, 0.85);
const recommendations = items.filter(item => item.score >= threshold);
JSON flags allow you to manage complex configuration objects.
In the Flagdeck dashboard, create a JSON flag by selecting "JSON" as the value type and providing a valid JSON structure.
// Get a complex configuration with default
const config = await flagdeck.getValue('service-config', context, {
url: 'https://api.default.com',
timeout: 5000,
retries: 3
});
// Use the config object properties
initiateService({
endpoint: config.url,
options: {
timeout: config.timeout,
retries: config.retries
}
});
With TypeScript, you can define the expected shape of your configuration:
interface APIConfig {
url: string;
timeout: number;
retries: number;
headers?: Record<string, string>;
}
// Get the config with proper type information
const config = await flagdeck.getValue<APIConfig>('api-config', context, {
url: 'https://api.default.com',
timeout: 5000,
retries: 3
});
// TypeScript provides full type checking
const apiClient = new ApiClient(config.url);
apiClient.setTimeout(config.timeout);
apiClient.setRetries(config.retries);
When you need additional metadata about an evaluation:
// Get the full evaluation result
const result = await flagdeck.evaluateFlag('new-feature', context);
console.log(`Feature is ${result.value ? 'enabled' : 'disabled'}`);
console.log(`Source: ${result.source}`); // 'api', 'cache', 'offline'
console.log(`Reason: ${result.reason}`);
console.log(`Evaluated at: ${new Date(result.timestamp)}`);
The full evaluation result contains:
value
: The actual flag valueflagKey
: The flag identifiersource
: Where the value came from ('api', 'cache', 'offline', 'error')reason
: Human-readable explanation of the decisiontimestamp
: When the evaluation occurrederror
: Error information if evaluation failedFor better performance, evaluate multiple flags in a single request:
// Get multiple flag values in a single request
const values = await flagdeck.getValues([
'feature-a',
'pricing-tier',
'item-limit'
], context);
// Access individual values
const featureAEnabled = values['feature-a']; // boolean
const pricingTier = values['pricing-tier']; // string
const itemLimit = values['item-limit']; // number
This is much more efficient than making separate calls for each flag.
Always provide default values when getting flag values to ensure your application works even if flag evaluation fails:
// With default value (recommended)
const limit = await flagdeck.getValue('rate-limit', context, 100);
// Without default value (not recommended)
const limit = await flagdeck.getValue('rate-limit', context);
// Could be undefined if the evaluation fails
Use Descriptive Keys: Choose flag keys that clearly describe their purpose (e.g., user-onboarding-v2
instead of flag-123
)
Consistent Types: Avoid changing a flag's value type after it's in use
Default Values: Always provide sensible defaults that match the expected type
Type Safety: Use TypeScript for improved safety when working with non-boolean flags
Bulk Evaluation: Use getValues()
when you need multiple flags at once to reduce network requests
Start using Flagdeck today
Simple feature flag management for modern development teams.
Product
© 2025 Flagdeck. All rights reserved.