Skip to content

Commit

Permalink
[FSSDK-9897] update return type of getFeatureVariable method (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
raju-opti authored Jan 2, 2024
1 parent 2b40193 commit 7e03647
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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,
FeatureVariableValue,
} 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;
): FeatureVariableValue {
let castValue : FeatureVariableValue;

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,
FeatureVariableValue,
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,
FeatureVariableValue,
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): FeatureVariableValue {
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 {
): FeatureVariableValue {
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 {
): FeatureVariableValue {
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 FeatureVariableValue = 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): FeatureVariableValue;
getFeatureVariableBoolean(
featureKey: string,
variableKey: string,
Expand Down

0 comments on commit 7e03647

Please sign in to comment.