diff --git a/lib/core/project_config/index.ts b/lib/core/project_config/index.ts index a58c9cdc2..07b206df6 100644 --- a/lib/core/project_config/index.ts +++ b/lib/core/project_config/index.ts @@ -32,6 +32,7 @@ import { VariableType, VariationVariable, Integration, + FeatureVariableValue, } from '../../shared_types'; interface TryCreatingProjectConfigConfig { @@ -692,8 +693,8 @@ export const getTypeCastValue = function( variableValue: string, variableType: VariableType, logger: LogHandler -): unknown { - let castValue; +): FeatureVariableValue { + let castValue : FeatureVariableValue; switch (variableType) { case FEATURE_VARIABLE_TYPES.BOOLEAN: diff --git a/lib/export_types.ts b/lib/export_types.ts index cfd498591..759bb86c0 100644 --- a/lib/export_types.ts +++ b/lib/export_types.ts @@ -22,6 +22,7 @@ export { UserAttributeValue, UserAttributes, OptimizelyConfig, + FeatureVariableValue, OptimizelyVariable, OptimizelyVariation, OptimizelyExperiment, diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index c2b26478e..a7c6c29fe 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -35,6 +35,7 @@ import { FeatureVariable, OptimizelyOptions, OptimizelyDecideOption, + FeatureVariableValue, OptimizelyDecision, Client, } from '../shared_types'; @@ -777,7 +778,7 @@ export default class Optimizely implements Client { * type, or null if the feature key is invalid or * the variable key is invalid */ - getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown { + getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue { try { if (!this.isValidInstance()) { this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable'); @@ -819,7 +820,7 @@ export default class Optimizely implements Client { variableType: string | null, userId: string, attributes?: UserAttributes - ): unknown { + ): FeatureVariableValue { if (!this.validateInputs({ feature_key: featureKey, variable_key: variableKey, user_id: userId }, attributes)) { return null; } @@ -911,7 +912,7 @@ export default class Optimizely implements Client { variation: Variation | null, variable: FeatureVariable, userId: string - ): unknown { + ): FeatureVariableValue { const configObj = this.projectConfigManager.getConfig(); if (!configObj) { return null; diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 5caf705f9..f156eaee4 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -311,6 +311,8 @@ export interface OptimizelyExperiment { }; } +export type FeatureVariableValue = number | string | boolean | object | null; + export interface OptimizelyVariable { id: string; key: string; @@ -330,7 +332,7 @@ export interface Client { getForcedVariation(experimentKey: string, userId: string): string | null; isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean; getEnabledFeatures(userId: string, attributes?: UserAttributes): string[]; - getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown; + getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue; getFeatureVariableBoolean( featureKey: string, variableKey: string,