Skip to content

Commit

Permalink
feat: Use enum to define type in getTypeCastValue (#695)
Browse files Browse the repository at this point in the history
* Use enum to define type

* NIT
  • Loading branch information
yavorona committed Jul 27, 2021
1 parent 3d8a5b8 commit 930c473
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/optimizely-sdk/lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
FeatureVariable,
Variation,
OptimizelyVariation,
VariationVariable,
VariableType,
VariationVariable
} from '../../shared_types';

interface TryCreatingProjectConfigConfig {
Expand Down Expand Up @@ -203,7 +204,7 @@ export const createProjectConfig = function(
// Converting it to a first-class json type while creating Project Config
feature.variables.forEach((variable) => {
if (variable.type === FEATURE_VARIABLE_TYPES.STRING && variable.subType === FEATURE_VARIABLE_TYPES.JSON) {
variable.type = FEATURE_VARIABLE_TYPES.JSON;
variable.type = FEATURE_VARIABLE_TYPES.JSON as VariableType;
delete variable.subType;
}
});
Expand Down Expand Up @@ -584,7 +585,7 @@ export const getVariableValueForVariation = function(
*/
export const getTypeCastValue = function(
variableValue: string,
variableType: string,
variableType: VariableType,
logger: LogHandler
): unknown {
let castValue;
Expand Down
10 changes: 9 additions & 1 deletion packages/optimizely-sdk/lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,16 @@ export interface Experiment {
forcedVariations?: { [key: string]: string };
}

export enum VariableType {
BOOLEAN = 'boolean',
DOUBLE = 'double',
INTEGER = 'integer',
STRING = 'string',
JSON = 'json',
}

export interface FeatureVariable {
type: string;
type: VariableType;
key: string;
id: string;
defaultValue: string;
Expand Down

0 comments on commit 930c473

Please sign in to comment.