diff --git a/packages/web/src/provider/in-memory-provider/flag-configuration.ts b/packages/web/src/provider/in-memory-provider/flag-configuration.ts index 05f507d44..6ab05b9ba 100644 --- a/packages/web/src/provider/in-memory-provider/flag-configuration.ts +++ b/packages/web/src/provider/in-memory-provider/flag-configuration.ts @@ -10,15 +10,15 @@ type Variants = Record; /** * A Feature Flag definition, containing it's specification */ -export type Flag = { +export type Flag | Variants | Variants | Variants> = { /** * An object containing all possible flags mappings (variant -> flag value) */ - variants: Variants | Variants | Variants | Variants; + variants: V; /** * The variant it will resolve to in STATIC evaluation */ - defaultVariant: string; + defaultVariant: keyof V; /** * Determines if flag evaluation is enabled or not for this flag. * If false, falls back to the default value provided to the client @@ -30,7 +30,26 @@ export type Flag = { * If it does not return a valid variant it falls back to the default value provided to the client * @param EvaluationContext */ - contextEvaluator?: (ctx: EvaluationContext) => string; + contextEvaluator?: (ctx: EvaluationContext) => keyof V; +}; + +// sample +const flag: Flag<{ + hi: boolean, + bye: boolean, +}> = { + variants: { + 'hi': true, + bye: false, + }, + disabled: false, + defaultVariant: 'hi', + contextEvaluator: (ctx: EvaluationContext) => { + if (ctx.user === 'bob@flags.com') { + return 'bye'; + } + return 'hi'; + }, }; export type FlagConfiguration = Record;