Skip to content

Commit 930c473

Browse files
authored
feat: Use enum to define type in getTypeCastValue (#695)
* Use enum to define type * NIT
1 parent 3d8a5b8 commit 930c473

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 4 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
});
@@ -584,7 +585,7 @@ export const getVariableValueForVariation = function(
584585
*/
585586
export const getTypeCastValue = function(
586587
variableValue: string,
587-
variableType: string,
588+
variableType: VariableType,
588589
logger: LogHandler
589590
): unknown {
590591
let castValue;

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,16 @@ export interface Experiment {
129129
forcedVariations?: { [key: string]: string };
130130
}
131131

132+
export enum VariableType {
133+
BOOLEAN = 'boolean',
134+
DOUBLE = 'double',
135+
INTEGER = 'integer',
136+
STRING = 'string',
137+
JSON = 'json',
138+
}
139+
132140
export interface FeatureVariable {
133-
type: string;
141+
type: VariableType;
134142
key: string;
135143
id: string;
136144
defaultValue: string;

0 commit comments

Comments
 (0)