Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[FSSDK-9897] update return type of getFeatureVariable method
  • Loading branch information
raju-opti committed Dec 28, 2023
commit e2e6025ea42502c357c361e5882de9b1446e5cb8
5 changes: 3 additions & 2 deletions lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
VariableType,
VariationVariable,
Integration,
OptimizelyVariableValue,
} from '../../shared_types';

interface TryCreatingProjectConfigConfig {
Expand Down Expand Up @@ -692,8 +693,8 @@ export const getTypeCastValue = function(
variableValue: string,
variableType: VariableType,
logger: LogHandler
): unknown {
let castValue;
): OptimizelyVariableValue {
let castValue : OptimizelyVariableValue;

switch (variableType) {
case FEATURE_VARIABLE_TYPES.BOOLEAN:
Expand Down
1 change: 1 addition & 0 deletions lib/export_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
UserAttributeValue,
UserAttributes,
OptimizelyConfig,
OptimizelyVariableValue,
OptimizelyVariable,
OptimizelyVariation,
OptimizelyExperiment,
Expand Down
7 changes: 4 additions & 3 deletions lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
FeatureVariable,
OptimizelyOptions,
OptimizelyDecideOption,
OptimizelyVariableValue,
OptimizelyDecision,
Client,
} from '../shared_types';
Expand Down Expand Up @@ -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): OptimizelyVariableValue {
try {
if (!this.isValidInstance()) {
this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable');
Expand Down Expand Up @@ -819,7 +820,7 @@ export default class Optimizely implements Client {
variableType: string | null,
userId: string,
attributes?: UserAttributes
): unknown {
): OptimizelyVariableValue {
if (!this.validateInputs({ feature_key: featureKey, variable_key: variableKey, user_id: userId }, attributes)) {
return null;
}
Expand Down Expand Up @@ -911,7 +912,7 @@ export default class Optimizely implements Client {
variation: Variation | null,
variable: FeatureVariable,
userId: string
): unknown {
): OptimizelyVariableValue {
const configObj = this.projectConfigManager.getConfig();
if (!configObj) {
return null;
Expand Down
4 changes: 3 additions & 1 deletion lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ export interface OptimizelyExperiment {
};
}

export type OptimizelyVariableValue = number | string | boolean | object | null;

export interface OptimizelyVariable {
id: string;
key: string;
Expand All @@ -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): OptimizelyVariableValue;
getFeatureVariableBoolean(
featureKey: string,
variableKey: string,
Expand Down