Skip to content

Commit f8f8e00

Browse files
committed
Use enum to define type
1 parent 1b0c036 commit f8f8e00

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/optimizely-sdk/lib/core/project_config/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import {
3535
FeatureVariable,
3636
Variation,
3737
OptimizelyVariation,
38-
VariationVariable,
38+
VariableType,
39+
VariationVariable
3940
} from '../../shared_types';
4041

4142
interface TryCreatingProjectConfigConfig {
@@ -203,7 +204,7 @@ export const createProjectConfig = function(
203204
// Converting it to a first-class json type while creating Project Config
204205
feature.variables.forEach((variable) => {
205206
if (variable.type === FEATURE_VARIABLE_TYPES.STRING && variable.subType === FEATURE_VARIABLE_TYPES.JSON) {
206-
variable.type = FEATURE_VARIABLE_TYPES.JSON;
207+
variable.type = FEATURE_VARIABLE_TYPES.JSON as VariableType;
207208
delete variable.subType;
208209
}
209210
});
@@ -582,9 +583,10 @@ export const getVariableValueForVariation = function(
582583
* @returns {*} Variable value of the appropriate type, or
583584
* null if the type cast failed
584585
*/
586+
585587
export const getTypeCastValue = function(
586588
variableValue: string,
587-
variableType: string,
589+
variableType: VariableType,
588590
logger: LogHandler
589591
): unknown {
590592
let castValue;

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,16 @@ export interface Experiment {
124124
forcedVariations?: { [key: string]: string };
125125
}
126126

127+
export enum VariableType {
128+
BOOLEAN = 'boolean',
129+
DOUBLE = 'double',
130+
INTEGER = 'integer',
131+
STRING = 'string',
132+
JSON = 'json',
133+
}
134+
127135
export interface FeatureVariable {
128-
type: string;
136+
type: VariableType;
129137
key: string;
130138
id: string;
131139
defaultValue: string;

0 commit comments

Comments
 (0)