Vexil/Docs/Evaluating flags
Dashboard

Evaluating flags

Get the value of any flag for the current user. One method — five flag types.

The evaluate() method

Call ff.evaluate(flagKey, context) to get a flag's value. Pass your user's ID so Vexil can apply gradual rollouts consistently for that person.

Boolean flag

ts
const enabled = await ff.evaluate<boolean>('dark-mode', {
  userId: 'user_123',
})

if (enabled) {
  // show dark theme
}

String flag

ts
const buttonCopy = await ff.evaluate<string>('checkout-button-copy', {
  userId: 'user_123',
})
// → "Buy now" | "Checkout" | "Get started"

Number flag

ts
const requestLimit = await ff.evaluate<number>('api-rate-limit', {
  userId: 'user_123',
})
// → 100 | 500 | 1000

JSON flag

ts
const config = await ff.evaluate<{ theme: string; maxItems: number }>('ui-config', {
  userId: 'user_123',
})
// → { theme: 'compact', maxItems: 20 }

Gradual rollout flag

ts
// For gradual flags, the userId is hashed — same user always gets the same result
const inBeta = await ff.evaluate<boolean>('new-dashboard', {
  userId: 'user_123',
})

Targeting a specific environment

ts
// Override the default environment for this call
const enabled = await ff.evaluate<boolean>('new-checkout', {
  userId: 'user_123',
  environment: 'staging',
})

Fallback values

Pass a third argument to evaluate() as a safe fallback if the API is unreachable. If omitted, the SDK uses the flag's configured default value.

ts
// If the API is down, return false instead of throwing
const enabled = await ff.evaluate('payment-v2', { userId }, false)
← PreviousInstallationNext →Tracking events