10000 [FSSDK-9897] update return type of getFeatureVariable method (#887) · optimizely/javascript-sdk@7e03647 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e03647

Browse files
authored
[FSSDK-9897] update return type of getFeatureVariable method (#887)
1 parent 2b40193 commit 7e03647

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

lib/core/project_config/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
VariableType,
3333
VariationVariable,
3434
Integration,
35+
FeatureVariableValue,
3536
} from '../../shared_types';
3637

3738
interface TryCreatingProjectConfigConfig {
@@ -692,8 +693,8 @@ export const getTypeCastValue = function(
692693
variableValue: string,
693694
variableType: VariableType,
694695
logger: LogHandler
695-
): unknown {
696-
let castValue;
696+
): FeatureVariableValue {
697+
let castValue : FeatureVariableValue;
697698

698699
switch (variableType) {
699700
case FEATURE_VARIABLE_TYPES.BOOLEAN:

lib/export_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
UserAttributeValue,
2323
UserAttributes,
2424
OptimizelyConfig,
25+
FeatureVariableValue,
2526
OptimizelyVariable,
2627
OptimizelyVariation,
2728
OptimizelyExperiment,

lib/optimizely/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
FeatureVariable,
3636
OptimizelyOptions,
3737
OptimizelyDecideOption,
38+
FeatureVariableValue,
3839
OptimizelyDecision,
3940
Client,
4041
} from '../shared_types';
< 10000 div class="d-flex flex-column">
@@ -777,7 +778,7 @@ export default class Optimizely implements Client {
777778
* type, or null if the feature key is invalid or
778779
* the variable key is invalid
779780
*/
780-
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown {
781+
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue {
781782
try {
782783
if (!this.isValidInstance()) {
783784
this.logger.log(LOG_LEVEL.ERROR, LOG_MESSAGES.INVALID_OBJECT, MODULE_NAME, 'getFeatureVariable');
@@ -819,7 +820,7 @@ export default class Optimizely implements Client {
819820
variableType: string | null,
820821
userId: string,
821822
attributes?: UserAttributes
822-
): unknown {
823+
): FeatureVariableValue {
823824
if (!this.validateInputs({ feature_key: featureKey, variable_key: variableKey, user_id: userId }, attributes)) {
824825
return null;
825826
}
@@ -911,7 +912,7 @@ export default class Optimizely implements Client {
911912
variation: Variation | null,
912913
variable: FeatureVariable,
913914
userId: string
914-
): unknown {
915+
): FeatureVariableValue {
915916
const configObj = this.projectConfigManager.getConfig();
916917
if (!configObj) {
917918
return null;

lib/shared_types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ export interface OptimizelyExperiment {
311311
};
312312
}
313313

314+
export type FeatureVariableValue = number | string | boolean | object | null;
315+
314316
export interface OptimizelyVariable {
315317
id: string;
316318
key: string;
@@ -330,7 +332,7 @@ export interface Client {
330332
getForcedVariation(experimentKey: string, userId: string): string | null;
331333
isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean;
332334
getEnabledFeatures(userId: string, attributes?: UserAttributes): string[];
333-
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown;
335+
getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): FeatureVariableValue;
334336
getFeatureVariableBoolean(
335337
featureKey: string,
336338
variableKey: string,

0 commit comments

Comments
 (0)
0